/// <summary>
        /// Recreate a SessionManager from state.
        /// </summary>
        /// <param name="sessionState">SessionState containing details captured from a previous SessionManager or null if no previous SessionManager.</param>
        /// <param name="sampleRate">Sample rate to determine likelyhood of a new installation being tracked or not.</param>
        /// <returns>Recreated SessionManager.</returns>
        public SessionManager(SessionState sessionState, double sampleRate = 100.0)
        {
            if (sessionState != null)
            {
                visitor = new Visitor(sessionState.VisitorId, sessionState.FirstVisitAt);
                Session = new Session(sessionState.SessionStartedAt, sessionState.SessionNumber, sessionState.SessionHitCount, sessionState.HitId);
                Referrer = sessionState.Referrer;
                PreviousSessionStartedAt = sessionState.PreviousSessionStartedAt;
                lastActivityAt = sessionState.LastActivityAt;
                SessionStatus = sessionState.SessionStatus;
                VisitorStatus = sessionState.VisitorStatus;
            }
            else
            {
                var localStorage = ApplicationData.Current.LocalSettings;
                Guid guid = Guid.Empty;
                if (localStorage.Values.ContainsKey(guidKey) ) {
                    guid =  (Guid)localStorage.Values[guidKey];
                } else {
                    // Need a better way to get a unique guid
                    guid = Guid.NewGuid();
                    localStorage.Values[guidKey] = guid;
                }

                visitor = new Visitor(guid);
                Session = new Session();
                PreviousSessionStartedAt = Session.StartedAt;
                SessionStatus = SessionStatus.Starting;
                var willTrackThisVisitor = ShouldTrackThisNewVisitor(sampleRate);
                VisitorStatus = willTrackThisVisitor ? VisitorStatus.Active : VisitorStatus.SampledOut;
                if (!willTrackThisVisitor)
                    Debug.WriteLine("Will not track this visitor. Sampling rate of {0} excluded them", sampleRate);
            }
        }
        public void UrchinTracker_CreateCookieSubstituteParameter()
        {
            var @event = new EventActivity("action", "catgory", "label", 123, true);
            var sessionState = new SessionState
                {
                    SessionNumber = 5,
                    VisitorId = new Guid("FFFCCBCB-9A87-4987-BD20-CE7C81F96CD2"),
                    FirstVisitAt = new DateTimeOffset(2012, 10, 10, 13, 14, 15, TimeSpan.Zero),
                    PreviousSessionStartedAt = new DateTimeOffset(2012, 12, 10, 13, 14, 15, TimeSpan.Zero),
                    SessionStartedAt = new DateTimeOffset(2012, 12, 14, 13, 14, 15, TimeSpan.Zero),
                };
            var sessionManager = new SessionManager(TimeSpan.FromMinutes(5), sessionState);

            var cookieSubstitute = UrchinTracker.CreateCookieSubstituteParameter(sessionManager, 1);

            Assert.AreEqual("__utma=1.1159017511.1349874855.1355145255.1355490855.5;", cookieSubstitute);
        }
        /// <summary>
        /// Recreate a SessionManager from state.
        /// </summary>
        /// <param name="timeout">How long before a session will expire if no activity is seen.</param>
        /// <param name="sessionState">SessionState containing details captured from a previous SessionManager.</param>
        /// <returns>Recreated SessionManager.</returns>
        public SessionManager(TimeSpan timeout, SessionState sessionState)
        {
            this.timeout = timeout;

            if (sessionState != null)
            {
                visitor = new Visitor(sessionState.VisitorId, sessionState.FirstVisitAt);
                Session = new Session(sessionState.SessionStartedAt, sessionState.SessionNumber, sessionState.SessionHitCount, sessionState.HitId);
                Referrer = sessionState.Referrer;
                PreviousSessionStartedAt = sessionState.PreviousSessionStartedAt;
                lastActivityAt = sessionState.LastActivityAt;
            }
            else
            {
                visitor = new Visitor();
                Session = new Session();
                PreviousSessionStartedAt = Session.StartedAt;
            }
        }
Example #4
0
 /// <summary>
 /// Recreate a SessionManager from state.
 /// </summary>
 /// <param name="sessionState">SessionState containing details captured from a previous SessionManager or null if no previous SessionManager.</param>
 /// <param name="sampleRate">Sample rate to determine likelyhood of a new installation being tracked or not.</param>
 /// <returns>Recreated SessionManager.</returns>
 public SessionManager(SessionState sessionState, double sampleRate = 100.0)
 {
     if (sessionState != null)
     {
         visitor = new Visitor(sessionState.VisitorId);
         Referrer = sessionState.Referrer;
         lastActivityAt = sessionState.LastActivityAt;
         SessionStatus = sessionState.SessionStatus;
         VisitorStatus = sessionState.VisitorStatus;
     }
     else
     {
         visitor = new Visitor();
         SessionStatus = SessionStatus.Starting;
         var willTrackThisVisitor = ShouldTrackThisNewVisitor(sampleRate);
         VisitorStatus = willTrackThisVisitor ? VisitorStatus.Active : VisitorStatus.SampledOut;
         if (!willTrackThisVisitor)
             Debug.WriteLine("Will not track this visitor. Sampling rate of {0} excluded them", sampleRate);
     }
 }
 /// <summary>
 /// Save the session state to preserve state between application launches.
 /// </summary>
 /// <returns>Task that completes when the session state has been saved.</returns>
 private static async Task SaveSessionState(SessionState sessionState)
 {
     await LocalFolderContractSerializer<SessionState>.SaveAsync(sessionState, SessionStateFileName);
 }
 /// <summary>
 /// Save the session state to preserve state between application launches.
 /// </summary>
 /// <returns>Task that completes when the session state has been saved.</returns>
 private static async Task SaveSessionState(SessionState sessionState)
 {
     await AppDataContractSerializer.Save(sessionState, SessionStateFileName);
 }
 public TimeoutSessionManager(SessionState sessionState, TimeSpan timeout)
     : base(sessionState)
 {
     this.timeout = timeout;
 }