Exemplo n.º 1
0
        private Google.Apis.Analytics.v3.DataResource.GaResource.GetRequest getRequest(QueryData queryData)
        {
            string metrics    = string.Join(",", queryData.Metrics);
            string dimensions = string.Join(",", queryData.Dimensions);
            string sort       = string.Join(",", queryData.SortingFields);
            string filter     = string.Join(";", queryData.Filters);
            string segment    = null;

            if (queryData.SegmentId != null)
            {
                segment = "gaid::" + queryData.SegmentId;
            }
            else
            {
                segment = string.Join(";", queryData.DynamicSegments);
            }
            try
            {
                var request = queryData.Service.Data.Ga.Get(queryData.ProfileId, queryData.From.ToString("yyyy-MM-dd"), queryData.To.ToString("yyyy-MM-dd"), metrics);
                request.Dimensions = dimensions;
                request.Sort       = sort;
                request.Filters    = filter;
                request.StartIndex = queryData.Skip;
                request.MaxResults = queryData.Take;
                request.Segment    = segment;
                return(request);
            }
            catch (Exception ex)
            {
                var requestExceprion = new GoogleAnalyticsRequestException("Can't get request", ex);
                throw requestExceprion;
            }
        }
Exemplo n.º 2
0
        public IEnumerable <T> Execute(QueryData queryData, Func <ContextDataModel, T> expression, FieldsMap fieldsMap)
        {
            var request = getRequest(queryData);

            try
            {
                GaData data = request.Fetch();
                return(getResult(data, expression, fieldsMap));
            }
            catch (Exception ex)
            {
                var requestExceprion = new GoogleAnalyticsRequestException("Can't fetch data", ex);
                throw requestExceprion;
            }
        }
Exemplo n.º 3
0
        public void ExecuteAsync(QueryData queryData, Func <ContextDataModel, T> expression, FieldsMap fieldsMap, Action <IEnumerable <T> > callback)
        {
            var request = getRequest(queryData);

            request.FetchAsync(lazyData =>
            {
                try
                {
                    GaData data = lazyData.GetResult();
                    callback(getResult(data, expression, fieldsMap));
                }
                catch (Exception ex)
                {
                    var requestExceprion = new GoogleAnalyticsRequestException("Can't fetch data", ex);
                    throw requestExceprion;
                }
            });
        }