예제 #1
0
        public JsonResult RealtimeVisitors()
        {
            try
            {
                var gaService = new GoogleAnalyticsService(
                    keyInformationFilePath: SiteConfiguration.GAKeyFilePath,
                    serviceAccount: SiteConfiguration.GAServiceAccount,
                    applicationName: SiteConfiguration.GAApplicationName);

                var data = gaService.GetRealtimeData(SiteConfiguration.GAApplicationName);

                return Json(data.RealtimeResults, JsonRequestBehavior.AllowGet);
            }
            catch (Exception) { }

            return Json(null, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        public JsonResult Visitors(string start, string end = "yesterday", string dimension = "ga:date")
        {
            try
            {
                var gaService = new GoogleAnalyticsService(
                     keyInformationFilePath: SiteConfiguration.GAKeyFilePath,
                     serviceAccount: SiteConfiguration.GAServiceAccount,
                     applicationName: SiteConfiguration.GAApplicationName);

                if (string.IsNullOrEmpty(start))
                    start = DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd");

                var data = gaService.GetSessions(SiteConfiguration.GAProfileID, start, end, dimension);

                return Json(data.Results, JsonRequestBehavior.AllowGet);
            }
            catch (Exception) { }

            return Json(null, JsonRequestBehavior.AllowGet);
        }