Beispiel #1
0
        private static string BuildSort(string field, bool descending = false)
        {
            if (string.IsNullOrWhiteSpace(field))
            {
                throw new ArgumentNullException("field", "sort field must be specified, see GaMetadata");
            }

            return(string.Format("{0}{1}", descending ? "-" : "", GaMetadata.WithPrefix(field)));
        }
        private DataResource.RealtimeResource.GetRequest AnalyticsRequest(Google.Apis.Analytics.v3.AnalyticsService service, IGoogleAnalyticsRequestConfiguration requestConfig)
        {
            var metrics    = string.Join(",", requestConfig.Metrics.Select(GaMetadata.WithRealtimePrefix));
            var dimensions = string.Join(",", requestConfig.Dimensions.Select(GaMetadata.WithRealtimePrefix));

            var gRequest = service.Data.Realtime.Get(
                GaMetadata.WithPrefix(requestConfig.ProfileId),
                metrics);

            gRequest.Dimensions = dimensions == "" ? null : dimensions;
            gRequest.MaxResults = requestConfig.MaxResults;
            gRequest.Filters    = requestConfig.Filter;
            gRequest.Sort       = requestConfig.Sort;

            return(gRequest);
        }
Beispiel #3
0
        private static string BuildFilter(string field, string @operator, string value)
        {
            if (string.IsNullOrWhiteSpace(field))
            {
                throw new ArgumentNullException("field", "filter field must be specified, see GaMetadata");
            }
            if (string.IsNullOrWhiteSpace(@operator))
            {
                throw new ArgumentNullException("@operator", "filter operator must be specified, see GaMetadata.FilterOperator");
            }
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentNullException("value", "filter value must be specified");
            }

            return(string.Format("{0}{1}{2}", GaMetadata.WithPrefix(field), @operator, value));
        }
Beispiel #4
0
        private DataResource.GaResource.GetRequest AnalyticsRequest(AnalyticsService service, IGoogleAnalyticsRequestConfiguration requestConfig)
        {
            var metrics    = string.Join(",", requestConfig.Metrics.Select(GaMetadata.WithPrefix));
            var dimensions = string.Join(",", requestConfig.Dimensions.Select(GaMetadata.WithPrefix));

            var gRequest = service.Data.Ga.Get(
                GaMetadata.WithPrefix(requestConfig.ProfileId),
                requestConfig.StartDate.ToString("yyyy-MM-dd"),
                requestConfig.EndDate.ToString("yyyy-MM-dd"),
                metrics);

            gRequest.Dimensions = dimensions;
            gRequest.MaxResults = requestConfig.MaxResults;
            gRequest.Filters    = requestConfig.Filter;
            gRequest.Sort       = requestConfig.Sort;
            gRequest.Segment    = requestConfig.Segment;

            return(gRequest);
        }
        private static Type GetDataType(RealtimeData.ColumnHeadersData gaColumn)
        {
            switch (gaColumn.DataType.ToLowerInvariant())
            {
            case "integer":
                return(typeof(int));

            case "double":
                return(typeof(double));

            case "currency":
                return(typeof(decimal));

            case "time":
                return(typeof(float));

            default:
                if (gaColumn.Name.ToLowerInvariant().Equals(GaMetadata.WithPrefix(GaMetadata.Dimensions.Time.Date)))
                {
                    return(typeof(DateTime));
                }
                return(typeof(string));
            }
        }