/// <summary> /// Create a new AnalyticsClient with a given configuration, session, environment and URI sender. /// </summary> /// <param name="configuration">Configuration of this Google Analytics Measurement Protocol client.</param> /// <param name="sessionManager">Session manager with visitor and session information.</param> /// <param name="environment">Provider of environmental information such as screen resolution.</param> /// <param name="sender">Action to take prepared URIs for Google Analytics and send them on.</param> public MeasurementAnalyticsClient(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment, Action<Uri> sender) { this.sessionManager = sessionManager; this.sender = sender; tracker = new MeasurementTracker(configuration, sessionManager, environment); }
/// <summary> /// Configure this MeasurementAnalyticsClient so it can start recording and sending analytics. /// </summary> /// <param name="configuration">Configuration settings for this client.</param> /// <param name="sessionManager">Session manager to store and retreive session state.</param> /// <param name="environment">Provider of environmental details such as screen resolution.</param> /// <param name="sender">Action delegate responsible for sending URIs to analytics.</param> public void Configure(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment, Action<Uri> sender) { Debug.Assert(tracker == null); var newTracker = new MeasurementTracker(configuration, sessionManager, environment, sender); while (queue.Count > 0) newTracker.Track(queue.Dequeue()); tracker = newTracker; }
public void MeasurementTracker_Track_Sends_Request() { var actual = new List<Uri>(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment(), actual.Add); tracker.Track(new ScreenViewActivity("Testing")); Assert.AreEqual(1, actual.Count); }
public void MeasurementTracker_Track_Does_Not_Send_Request_When_Opted_Out() { var actual = new List<Uri>(); var sessionManager = MeasurementTestHelpers.CreateSessionManager(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, sessionManager, MeasurementTestHelpers.CreateEnvironment(), actual.Add); sessionManager.VisitorStatus = VisitorStatus.OptedOut; tracker.Track(new ScreenViewActivity("Testing")); Assert.AreEqual(0, actual.Count); }
public void MeasurementTracker_Track_Ends_Session() { var actual = new List<Uri>(); var sessionManager = MeasurementTestHelpers.CreateSessionManager(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, sessionManager, MeasurementTestHelpers.CreateEnvironment(), actual.Add); tracker.Track(new ScreenViewActivity("Testing") { EndSession = true }); Assert.AreEqual(SessionStatus.Ending, sessionManager.SessionStatus); StringAssert.Contains(actual.Last().OriginalString, "sc=end"); }
/// <summary> /// Event to allow you to hook in to capture or modify activities. /// </summary> //public event EventHandler<MeasurementActivity> OnTrack = delegate { }; /// <summary> /// Configure this MeasurementAnalyticsClient so it can start recording and sending analytics. /// </summary> /// <param name="configuration">Configuration settings for this client.</param> /// <param name="sessionManager">Session manager to store and retreive session state.</param> /// <param name="environment">Provider of environmental details such as screen resolution.</param> /// <param name="sender">Action delegate responsible for sending URIs to analytics.</param> public void Configure(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment, Action <Uri> sender) { Debug.Assert(tracker == null); var newTracker = new MeasurementTracker(configuration, sessionManager, environment, sender); while (queue.Count > 0) { newTracker.Track(queue.Dequeue()); } tracker = newTracker; }
public void MeasurementTracker_Track_Carries_Forward_Last_Transaction() { var actual = new List<Uri>(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment(), actual.Add); var transaction = new TransactionActivity { OrderId = "123", Currency = "GBP" }; tracker.Track(transaction); var transactionItem = new TransactionItemActivity("ABC", "Unit Test", 1.23m, 4); tracker.Track(transactionItem); Assert.AreEqual(transaction, transactionItem.Transaction); StringAssert.Contains(actual.Last().OriginalString, "ti=123"); }
public void MeasurementTracker_Track_Does_Not_Buffer_While_Opted_Out() { var actual = new List<Uri>(); var sessionManager = MeasurementTestHelpers.CreateSessionManager(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, sessionManager, MeasurementTestHelpers.CreateEnvironment(), actual.Add); sessionManager.VisitorStatus = VisitorStatus.OptedOut; tracker.Track(new ScreenViewActivity("OptedOut")); sessionManager.VisitorStatus = VisitorStatus.Active; tracker.Track(new ScreenViewActivity("OptedIn")); Assert.AreEqual(1, actual.Count); StringAssert.Contains(actual[0].OriginalString, "cd=OptedIn"); }
public void MeasurementTracker_Track_Hits_Session() { var actual = new List<Uri>(); var sessionManager = MeasurementTestHelpers.CreateSessionManager(); var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, sessionManager, MeasurementTestHelpers.CreateEnvironment(), actual.Add); tracker.Track(new MeasurementActivityEntry(new AppViewActivity("Testing"))); Assert.AreEqual(1, sessionManager.Session.HitCount); }