Ejemplo n.º 1
0
        /// <summary>
        /// Get Product Performance
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public StatsApiResult GetProductPerformance(string profile, DateTime? startDate, DateTime? endDate)
        {
            if (!startDate.HasValue)
                startDate = DateTime.Now.Subtract(TimeSpan.FromDays(31));
            if (!endDate.HasValue)
                endDate = DateTime.Now;
            //Profile, Start Date, End Date, Metrics (Array), Dimensions (Array)

            AnalyticsDataResponse data = GetGoogleService().Analytics.GetData(profile, new AnalyticsDataOptions
            {
                StartDate = startDate.Value,
                EndDate = endDate.Value,
                Metrics = AnalyticsMetric.UniquePurchases + AnalyticsMetric.ItemRevenue + AnalyticsMetric.RevenuePerItem + AnalyticsMetric.ItemsPerPurchase,
                Dimensions = AnalyticsDimension.ProductSku + AnalyticsDimension.ProductName,
                Sorting = new AnalyticsSortOptions().AddDescending(AnalyticsMetric.ItemRevenue)
            });

            //Store API result in our new object along with chart data
            var productsResult = new StatsApiResult();
            productsResult.ApiResult = data;                             //The data back from Google's API
            productsResult.ChartData = ChartHelper.GetChartData(data);   //Add chart data to device result via Helper

            // Return the data as JSON
            return productsResult;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get Transactions
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public StatsApiResult GetTransactions(string profile, DateTime? startDate, DateTime? endDate)
        {
            if (!startDate.HasValue)
                startDate = DateTime.Now.Subtract(TimeSpan.FromDays(31));
            if (!endDate.HasValue)
                endDate = DateTime.Now;
            //Profile, Start Date, End Date, Metrics (Array), Dimensions (Array)

            AnalyticsDataResponse data = GetGoogleService().Analytics.GetData(profile, new AnalyticsDataOptions
            {
                StartDate = startDate.Value,
                EndDate = endDate.Value,
                Metrics = AnalyticsMetric.Transactions + AnalyticsMetric.TransactionRevenue,
                Dimensions = AnalyticsDimension.TransactionId,
                Sorting = new AnalyticsSortOptions().AddDescending(AnalyticsMetric.Transactions)
            });

            //Store API result in our new object along with chart data
            var transactionsResult = new StatsApiResult();
            transactionsResult.ApiResult = data;                             //The data back from Google's API
            transactionsResult.ChartData = ChartHelper.GetChartData(data);   //Add chart data to device result via Helper

            // Return the data as JSON
            return transactionsResult;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public StatsApiResult GetCountry(string profile, DateTime?startDate, DateTime?endDate)
        {
            if (!startDate.HasValue)
            {
                startDate = DateTime.Now.Subtract(TimeSpan.FromDays(31));
            }
            if (!endDate.HasValue)
            {
                endDate = DateTime.Now;
            }
            //Profile, Start Date, End Date, Metrics (Array), Dimensions (Array)

            AnalyticsDataResponse data = GetGoogleService().Analytics.GetData(profile, new AnalyticsDataOptions {
                StartDate  = startDate.Value,
                EndDate    = endDate.Value,
                Metrics    = AnalyticsMetric.Visits + AnalyticsMetric.Pageviews,
                Dimensions = AnalyticsDimension.Country,
                Sorting    = new AnalyticsSortOptions().AddDescending(AnalyticsMetric.Visits)
            });

            //Store API result in our new object along with chart data
            var countryResult = new StatsApiResult();

            countryResult.ApiResult = data;                                 //The data back from Google's API
            countryResult.ChartData = ChartHelper.GetGeoChartData(data);    //Add chart data to device result via Helper

            // Return the data as JSON
            return(countryResult);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            //Get Current User
            var currentUser = User.GetCurrent();

            //This will only run on the analyticsTree & if the user is NOT admin
            if (sender.TreeAlias == "analyticsTree" && !currentUser.IsAdmin())
            {
                //setting node to remove
                var settingNode = e.Nodes.SingleOrDefault(x => x.Id.ToString() == "settings");

                //Ensure we found the node
                if (settingNode != null)
                {
                    //Remove the settings node from the collection
                    e.Nodes.Remove(settingNode);
                }
            }

            //This will only run on the analyticsTree
            if (sender.TreeAlias == "analyticsTree")
            {
                AnalyticsApiController gaApi = new AnalyticsApiController();

                Profile profile = AnalyticsHelpers.GetProfile();

                if (profile != null)
                {
                    var ecommerceNode = e.Nodes.SingleOrDefault(x => x.Id.ToString() == "ecommerce");
                    if (ecommerceNode != null)
                    {
                        try
                        {
                            // check if profile has any ecommerce data for last 3 years
                            StatsApiResult transactions = gaApi.GetTransactions(profile.Id, DateTime.Now.AddYears(-3), DateTime.Now);
                            if (!transactions.ApiResult.Rows.Any())
                            {
                                //Remove the ecommerce node from the collection
                                //If no Rows returned from API - then remove the node from the tree
                                e.Nodes.Remove(ecommerceNode);
                            }
                        }
                        catch
                        {
                            //Remove the ecommerce node from the collection
                            //If the API throws an ex then remove the node from the tree as well
                            e.Nodes.Remove(ecommerceNode);
                        }
                    }
                }
            }
        }