public async Task<IGoogleAnalyticsResponse> QueryAsync(IGoogleAnalyticsRequestConfiguration requestConfig)
        {
            using (var svc = AnalyticsService)
            {
                try
                {
                    var gRequest = AnalyticsRequest(svc, requestConfig);

                    var data = await gRequest.ExecuteAsync();
                    var dt = ToDataTable(data, data.ProfileInfo.ProfileName);

                    while (data.NextLink != null && data.Rows != null)
                    {
                        gRequest.StartIndex = (gRequest.StartIndex ?? 1) + data.Rows.Count;
                        data = await gRequest.ExecuteAsync();
                        dt.Merge(ToDataTable(data));
                    }
                    return new GoogleAnalyticsResponse(requestConfig, 
                        true,
                        new GoogleAnalyticsDataResponse(dt, data.ContainsSampledData.GetValueOrDefault(false)));
                }
                catch (Exception ex)
                {
                    return new GoogleAnalyticsResponse(requestConfig, 
                        false, errorResponse: new GoogleAnalyticsErrorResponse(ex.Message, ex));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <IGoogleAnalyticsResponse> QueryAsync(IGoogleAnalyticsRequestConfiguration requestConfig)
        {
            using (var svc = AnalyticsService)
            {
                try
                {
                    var gRequest = AnalyticsRequest(svc, requestConfig);

                    var data = await gRequest.ExecuteAsync();

                    var dt = ToDataTable(data, data.ProfileInfo.ProfileName);

                    while (data.NextLink != null && data.Rows != null)
                    {
                        if (requestConfig.MaxResults < 10000 && data.Rows.Count <= requestConfig.MaxResults)
                        {
                            break;
                        }
                        gRequest.StartIndex = (gRequest.StartIndex ?? 1) + data.Rows.Count;
                        data = await gRequest.ExecuteAsync();

                        dt.Merge(ToDataTable(data));
                    }
                    return(new GoogleAnalyticsResponse(requestConfig,
                                                       true,
                                                       new GoogleAnalyticsDataResponse(dt, data.ContainsSampledData.GetValueOrDefault(false))));
                }
                catch (Exception ex)
                {
                    return(new GoogleAnalyticsResponse(requestConfig,
                                                       false, errorResponse: new GoogleAnalyticsErrorResponse(ex.Message, ex)));
                }
            }
        }
 internal GoogleAnalyticsResponse(IGoogleAnalyticsRequestConfiguration requestConfig, bool isSuccess, IGoogleAnalyticsDataResponse dataResponse = null,
                                  IGoogleAnalyticsErrorResponse errorResponse = null)
 {
     Success = isSuccess;
     Data    = dataResponse;
     Error   = errorResponse;
     _requestConfigExporter = requestConfig as IGoogleAnalyticsRequestConfigurationExporter;
 }
 internal GoogleAnalyticsResponse(IGoogleAnalyticsRequestConfiguration requestConfig, bool isSuccess, IGoogleAnalyticsDataResponse dataResponse = null,
     IGoogleAnalyticsErrorResponse errorResponse = null)
 {
     Success = isSuccess;
     Data = dataResponse;
     Error = errorResponse;
     _requestConfigExporter = requestConfig as IGoogleAnalyticsRequestConfigurationExporter;
 }
        public async Task <IGoogleAnalyticsResponse> QueryAsync(IGoogleAnalyticsRequestConfiguration requestConfig)
        {
            using (var svc = AnalyticsService)
            {
                try
                {
                    var gRequest = AnalyticsRequest(svc, requestConfig);

                    var data = await gRequest.ExecuteAsync();

                    var dt = ToDataTable(data, data.ProfileInfo.ProfileName);

                    return(new GoogleAnalyticsResponse(requestConfig, true, new GoogleAnalyticsDataResponse(dt, false)));
                }
                catch (Exception ex)
                {
                    return(new GoogleAnalyticsResponse(requestConfig, false, errorResponse: new GoogleAnalyticsErrorResponse(ex.Message, ex)));
                }
            }
        }
 public IGoogleAnalyticsResponse Query(IGoogleAnalyticsRequestConfiguration requestConfig)
 {
     return(Task.Run(() => QueryAsync(requestConfig)).Result);
 }
        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);
        }
 public IGoogleAnalyticsResponse Query(IGoogleAnalyticsRequestConfiguration requestConfig)
 {
     return Task.Run(() => QueryAsync(requestConfig)).Result;
 }
        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;
        }
Ejemplo n.º 10
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);
        }