예제 #1
0
        static Analytics()
        {
#if __PC__
            if (Settings.Default.GUID == "00000000-0000-0000-0000-000000000000")
            {
                Settings.Default.GUID = Guid.NewGuid().ToString();
                Settings.Default.Save();
            }
            GUID = Settings.Default.GUID;
            OperatingSystem os = Environment.OSVersion;
            trackerEnvironment = new SimpleTrackerEnvironment(os.Platform.ToString(), os.Version.ToString(), os.VersionString);
            analyticsSession   = new AnalyticsSession();
            tracker            = new SimpleTracker("UA-125850339-2", analyticsSession, trackerEnvironment);
            AppVersion         = MainForm.VERSION;
            OSVersion          = SetWindowsVersion(os.Version.ToString());
            bool windowsStoreApp = Application.ExecutablePath.Contains("WindowsApps");
            bool debugging       = Application.ExecutablePath.Contains("GitRepo");
            DeploymentType = windowsStoreApp ? "Windows Store" : debugging ? "Development" : "Zip File";
            string resolution = Screen.PrimaryScreen.Bounds.ToString();
#elif __MACOS__
            var userDefaults = new NSUserDefaults();
            GUID = userDefaults.StringForKey("AnalyticsKey");
            if (string.IsNullOrEmpty(GUID))
            {
                GUID = Guid.NewGuid().ToString();
                userDefaults.SetString(GUID, "AnalyticsKey");
                userDefaults.Synchronize();
            }
            NSProcessInfo info = new NSProcessInfo();
            OSVersion          = $"MacOSX {info.OperatingSystemVersionString}";
            trackerEnvironment = new SimpleTrackerEnvironment("Mac OSX", info.OperatingSystemVersion.ToString(), OSVersion);
            analyticsSession   = new AnalyticsSession();
            tracker            = new SimpleTracker("UA-125850339-2", analyticsSession, trackerEnvironment);
            var app = (AppDelegate)NSApplication.SharedApplication.Delegate;
            AppVersion     = FamilyTree.Instance.Version;
            DeploymentType = "Mac Website";
            string resolution = NSScreen.MainScreen.Frame.ToString();
#elif __IOS__
            var userDefaults = new NSUserDefaults();
            GUID = userDefaults.StringForKey("AnalyticsKey");
            if (string.IsNullOrEmpty(GUID))
            {
                GUID = Guid.NewGuid().ToString();
                userDefaults.SetString(GUID, "AnalyticsKey");
                userDefaults.Synchronize();
            }
            NSProcessInfo info = new NSProcessInfo();
            OSVersion          = $"MacOSX {info.OperatingSystemVersionString}";
            trackerEnvironment = new SimpleTrackerEnvironment("Mac OSX", info.OperatingSystemVersion.ToString(), OSVersion);
            analyticsSession   = new AnalyticsSession();
            tracker            = new SimpleTracker("UA-125850339-2", analyticsSession, trackerEnvironment);
            var app = (AppDelegate)UIApplication.SharedApplication.Delegate;
            AppVersion     = FamilyTree.Instance.Version;
            DeploymentType = "Mac Website";
            string resolution = UIScreen.MainScreen.Bounds.ToString();
#endif
            Resolution = resolution.Length > 11 ? resolution.Substring(9, resolution.Length - 10) : resolution;
        }
예제 #2
0
        protected override void HandleNewRequest(AnalyticsSession session, string operationName, string operationId)
        {
            _requestContext.Set(AnalyticsHeaders.Operation.Name, operationName);
            _requestContext.Set(AnalyticsHeaders.Operation.Id, operationId);

            _requestContext.Set(AnalyticsHeaders.Session.Id, session.Id);
            _requestContext.Set(AnalyticsHeaders.Session.AccountId, session.AccountId);
            _requestContext.Set(AnalyticsHeaders.Session.UserId, session.UserId);
            _requestContext.Set(AnalyticsHeaders.Session.DeviceId, session.DeviceId);
            _requestContext.Set(AnalyticsHeaders.Session.AppVersion, session.AppVersion);
        }
        public async Task <TrackingResult> TrackPageViewAsync(string pageTitle, string pageUrl)
        {
            var pageViewParameters = new PageView {
                DocumentTitle       = pageTitle,
                DocumentLocationUrl = pageUrl,
                CacheBuster         = AnalyticsSession.GenerateCacheBuster(),
                ViewportSize        = ViewportSize,
                ScreenResolution    = ScreenResolution,
                ClientId            = ClientId,
                UserId = UserId
            };

            return(await TrackAsync(pageViewParameters));
        }
예제 #4
0
        public void LogPageView(PageViewInfo info)
        {
            User          user          = _getCurrentUser.Get();
            var           site          = _session.Get <Site>(_site.Id);
            DateTime      now           = CurrentRequestData.Now;
            AnalyticsUser analyticsUser = GetCurrentUser(user == null ? info.User : user.Guid);
            bool          userIsNew     = analyticsUser == null;

            if (userIsNew)
            {
                analyticsUser = new AnalyticsUser
                {
                    User      = user,
                    CreatedOn = now,
                    UpdatedOn = now,
                };
                analyticsUser.SetGuid(info.User);
                _session.Insert(analyticsUser);
            }
            AnalyticsSession analyticsSession = GetCurrentSession(info.Session);
            bool             sessionIsNew     = analyticsSession == null;

            if (sessionIsNew)
            {
                analyticsSession = new AnalyticsSession
                {
                    AnalyticsUser = analyticsUser,
                    IP            = _request.GetCurrentIP(),
                    UserAgent     = _request.UserAgent,
                    Site          = site,
                    CreatedOn     = now,
                    UpdatedOn     = now,
                };
                analyticsSession.SetGuid(info.Session);
                _session.Insert(analyticsSession);
            }

            var pageView = new AnalyticsPageView
            {
                Webpage          = GetWebpage(info.Url),
                Url              = info.Url,
                AnalyticsSession = analyticsSession,
                Site             = site,
                CreatedOn        = now,
                UpdatedOn        = now,
            };

            _session.Insert(pageView);
        }
        public async Task <TrackingResult> TrackScreenviewAsync(string screenName)
        {
            var screenviewParamenters = new ScreenviewTracking {
                ApplicationName    = appName,
                ApplicationId      = appId,
                ApplicationVersion = appVersion,
                ScreenName         = screenName,
                CacheBuster        = AnalyticsSession.GenerateCacheBuster(),
                ViewportSize       = ViewportSize,
                ScreenResolution   = ScreenResolution,
                ClientId           = ClientId,
                UserId             = UserId
            };

            return(await TrackAsync(screenviewParamenters));
        }
예제 #6
0
        public static void Log(string path, string pageName)
        {
            if (session == null)
            {
                session = new AnalyticsSession("officedev.github.io/Office-IT-Pro-Deployment-Scripts/InstallGenerator",
                                               "UA-70271323-2");
            }


            var page = session.CreatePageViewRequest(
                path,        // path
                pageName);   // page title

            // or send page views manually
            page.Send();
        }
예제 #7
0
파일: Telemetry.cs 프로젝트: talmuth/unBand
        private static void Init()
        {
            _session = new AnalyticsSession("http://unband.nachmore.com/app", "UA-56820272-3");

            var props = Settings.Current;

            _client = _session.CreatePageViewRequest("/", "Global");

            if (props.FirstRun)
            {
                TrackEvent(TelemetryCategory.General, "Install", props.Device);

                // TODO: would be nice to fire a new OS event on system upgrade
                TrackEvent(TelemetryCategory.General, "OS", GetOS());
            }
        }
예제 #8
0
        public IAnalyticsSession CreateSession()
        {
            var session = AnalyticsSession.FromExisting((string)_requestContext.Get(AnalyticsHeaders.Session.Id));

            session.UserId     = (string)_requestContext.Get(AnalyticsHeaders.Session.UserId);
            session.DeviceId   = (string)_requestContext.Get(AnalyticsHeaders.Session.DeviceId);
            session.AppVersion = (string)_requestContext.Get(AnalyticsHeaders.Session.AppVersion);
            session.AccountId  = (string)_requestContext.Get(AnalyticsHeaders.Session.AccountId);

            var currentOperationId   = (string)_requestContext.Get(AnalyticsHeaders.Operation.Id);
            var currentOperationName = (string)_requestContext.Get(AnalyticsHeaders.Operation.Name);

            session.SetProperty("OperationId", currentOperationId);
            session.SetProperty("OperationName", currentOperationName);

            return(session);
        }
예제 #9
0
        public void ApplicationStart()
        {
            if (_analyticsSession == null)
            {
                _analyticsSession = new AnalyticsSession(Domain, GaCode);
            }

            _page = _analyticsSession.CreatePageViewRequest(
                "/",     // path
                "Main"); // page title

            _apptimer = _page.StartTiming("Application", "WPF", "ExecutionTime");

            _page.SendEvent("Application", "AppStart", string.Empty, "1");

            _page.Send();
        }
예제 #10
0
        public static int TotalViewsFor(this HtmlHelper helper, Webpage webpage)
        {
            if (webpage == null)
            {
                return(0);
            }

            var session = helper.ViewContext.HttpContext.Get <ISession>();

            AnalyticsPageView pageView         = null;
            AnalyticsSession  analyticsSession = null;
            AnalyticsUser     analyticsUser    = null;
            IQueryOver <AnalyticsPageView, AnalyticsPageView> queryOver = session.QueryOver(() => pageView)
                                                                          .JoinAlias(() => pageView.AnalyticsSession, () => analyticsSession)
                                                                          .JoinAlias(() => analyticsSession.AnalyticsUser, () => analyticsUser)
                                                                          .Where(x => x.Webpage.Id == webpage.Id);


            PageViewResult result     = null;
            var            viewResult = queryOver
                                        .SelectList(builder =>
                                                    builder
                                                    .SelectGroup(() => pageView.Url)
                                                    .WithAlias(() => result.Url)
                                                    .SelectGroup(() => pageView.Webpage.Id)
                                                    .WithAlias(() => result.WebpageId)
                                                    .SelectCountDistinct(() => analyticsUser.Id)
                                                    .WithAlias(() => result.Unique)
                                                    .SelectCountDistinct(() => analyticsSession.Id)
                                                    .WithAlias(() => result.Sessions)
                                                    .SelectCountDistinct(() => pageView.Id)
                                                    .WithAlias(() => result.Total)
                                                    )
                                        .TransformUsing(Transformers.AliasToBean <PageViewResult>())
                                        .Take(1).SingleOrDefault <PageViewResult>();

            return(viewResult == null ? 0 : viewResult.Total);
        }
예제 #11
0
        private static void Init()
        {
            _session = new AnalyticsSession("http://toastify.nachmore.com/app", "UA-61123985-2");

            var settings = SettingsXml.Current;

            // abort asap if we are surpressing analytics
            if (settings.PreventAnalytics)
            {
                return;
            }

            _session.SetCustomVariable(1, "OS Version", GetOS());

            _client = _session.CreatePageViewRequest("/", "Global");

            if (SettingsXml.Current.FirstRun)
            {
                TrackEvent(TelemetryCategory.General, "Install", GetOS());

                SettingsXml.Current.FirstRun = false;
            }
        }
예제 #12
0
        public ThreeViewModel(AnalyticsSession analytics)
        {
            var page = analytics.CreatePageViewRequest("/three", "");

            page.Track(this);
        }
예제 #13
0
 public Tracking(string sitename, string siteid)
 {
     tracker = new AnalyticsSession(sitename, siteid);
 }
예제 #14
0
        private void UpdateOldUsersSessions(AnalyticsHttpContextExtensions.AnalyticsUserChangedResult changedResult, AnalyticsSession analyticsSession, AnalyticsUser analyticsUser)
        {
            if (!changedResult.OldGuid.HasValue || analyticsUser.Guid == changedResult.OldGuid.Value)
            {
                return;
            }

            _session.Transact(session =>
            {
                analyticsSession.AnalyticsUser = analyticsUser;
                _session.Update(analyticsSession);

                var oldUser = GetUser(changedResult.OldGuid.Value);
                if (oldUser != null && oldUser.Id != analyticsUser.Id)
                {
                    // this must have been the current user, so move over their sessions
                    var analyticsSessions =
                        _session.QueryOver <AnalyticsSession>().Where(x => x.AnalyticsUser.Id == oldUser.Id).List();
                    foreach (var entity in analyticsSessions)
                    {
                        entity.AnalyticsUser = analyticsUser;
                        _session.Update(entity);
                    }
                    _session.Delete(oldUser);
                }
            });
        }
예제 #15
0
        public void LogPageView(PageViewInfo info)
        {
            User          user          = _getCurrentUser.Get();
            var           site          = _session.Get <Site>(_site.Id);
            DateTime      now           = CurrentRequestData.Now;
            AnalyticsUser analyticsUser = GetUser(user == null ? info.User : user.Guid);
            bool          userIsNew     = analyticsUser == null;

            if (userIsNew)
            {
                analyticsUser = new AnalyticsUser
                {
                    User      = user,
                    CreatedOn = now,
                    UpdatedOn = now,
                };
                analyticsUser.SetGuid(info.User);
                _session.Insert(analyticsUser);
            }

            if (analyticsUser.RequiresEmailCheck && _getEmailFromRequest.CanCheck)
            {
                CheckEmail(analyticsUser, now);
            }

            AnalyticsSession analyticsSession = GetCurrentSession(info.Session);
            bool             sessionIsNew     = analyticsSession == null;
            var changedResult = _context.AnalyticsUserGuidHasChanged();

            if (sessionIsNew)
            {
                analyticsSession = new AnalyticsSession
                {
                    AnalyticsUser = analyticsUser,
                    IP            = _context.GetCurrentIP(),
                    UserAgent     = _context.Request.UserAgent,
                    Site          = site,
                    CreatedOn     = now,
                    UpdatedOn     = now,
                };
                analyticsSession.SetGuid(info.Session);
                _session.Insert(analyticsSession);
            }
            // only move it if it's going to a live user
            else if (changedResult.Changed && analyticsUser.User != null)
            {
                UpdateOldUsersSessions(changedResult, analyticsSession, analyticsUser);
            }

            var pageView = new AnalyticsPageView
            {
                Webpage          = GetWebpage(info.Url),
                Url              = info.Url,
                AnalyticsSession = analyticsSession,
                Site             = site,
                CreatedOn        = now,
                UpdatedOn        = now,
            };

            _session.Insert(pageView);
        }
        public GoogleAnalyticsPage(AnalyticsSession analyticsSession, string pageName)
        {
            _pageName = pageName;

            _page = analyticsSession.CreatePageViewRequest(pageName, pageName);
        }
예제 #17
0
        public IPagedList <PageViewResult> Search(PageViewSearchQuery query)
        {
            AnalyticsPageView pageView         = null;
            AnalyticsSession  analyticsSession = null;
            AnalyticsUser     analyticsUser    = null;
            IQueryOver <AnalyticsPageView, AnalyticsPageView> queryOver = _session.QueryOver(() => pageView)
                                                                          .JoinAlias(() => pageView.AnalyticsSession, () => analyticsSession)
                                                                          .JoinAlias(() => analyticsSession.AnalyticsUser, () => analyticsUser);

            if (!string.IsNullOrWhiteSpace(query.Url))
            {
                queryOver = queryOver.Where(view => view.Url.IsInsensitiveLike(query.Url, MatchMode.Anywhere));
            }

            queryOver = queryOver.Where(() => pageView.CreatedOn >= query.From && pageView.CreatedOn <= query.To);

            switch (query.SearchType)
            {
            case PageViewSearchType.UsersOnly:
                queryOver = queryOver.Where(() => analyticsUser.User != null);
                break;

            case PageViewSearchType.AnonymousOnly:
                queryOver = queryOver.Where(() => analyticsUser.User == null);
                break;
            }

            PageViewResult result = null;
            IPagedList <PageViewResult> pageViewResults = queryOver
                                                          .SelectList(builder =>
                                                                      builder
                                                                      .SelectGroup(() => pageView.Url)
                                                                      .WithAlias(() => result.Url)
                                                                      .SelectGroup(() => pageView.Webpage.Id)
                                                                      .WithAlias(() => result.WebpageId)
                                                                      .SelectCountDistinct(() => analyticsUser.Id)
                                                                      .WithAlias(() => result.Unique)
                                                                      .SelectCountDistinct(() => analyticsSession.Id)
                                                                      .WithAlias(() => result.Sessions)
                                                                      .SelectCountDistinct(() => pageView.Id)
                                                                      .WithAlias(() => result.Total)
                                                                      )
                                                          .TransformUsing(Transformers.AliasToBean <PageViewResult>())
                                                          .OrderBy(Projections.CountDistinct(() => analyticsUser.Id)).Desc
                                                          .ThenBy(Projections.CountDistinct(() => analyticsSession.Id)).Desc
                                                          .ThenBy(Projections.CountDistinct(() => pageView.Id)).Desc
                                                          .Paged <AnalyticsPageView, PageViewResult>(Projections.CountDistinct(() => pageView.Url), query.Page, enableCache: false); //todo enable cache when Nhibernate is updated to 4.1

            List <int?> ids = pageViewResults.Select(viewResult => viewResult.WebpageId).Where(i => i.HasValue).ToList();
            Dictionary <int, Webpage> webpages =
                _session.QueryOver <Webpage>()
                .Where(webpage => webpage.Id.IsIn(ids))
                .Cacheable()
                .List()
                .ToDictionary(webpage => webpage.Id, webpage => webpage);

            foreach (PageViewResult pageViewResult in pageViewResults)
            {
                if (!pageViewResult.WebpageId.HasValue)
                {
                    continue;
                }
                if (!webpages.ContainsKey(pageViewResult.WebpageId.Value))
                {
                    continue;
                }
                pageViewResult.WebpageName = webpages[pageViewResult.WebpageId.Value].Name;
            }

            return(pageViewResults);
        }
예제 #18
0
 /// <summary>
 /// Starts the analytics service.
 /// </summary>
 public void Start()
 {
     this.Session = new AnalyticsSession(AnalyticsService.AnalyticsUrl, AnalyticsService.GoogleAnalyticsCode);
 }
 public void Init()
 {
     instance = new AnalyticsSession();
 }
예제 #20
0
 public FourViewModel(AnalyticsSession analytics)
 {
     m_page = analytics.CreatePageViewRequest("/four", "");
     m_page.Track(this);
 }