public void TrackContentView_Tracks_ContentView()
        {
            var          url         = new Uri("http://csharpanalytics.com/doc");
            const string title       = "CSharpAnalytics docs";
            const string description = "Documentation for CSharpAnalaytics";
            const string path        = "/docs";
            const string hostName    = "docs.csharpanalytics.com";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackContentView(url, title, description, path, hostName);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=pageview");
            CollectionAssert.Contains(parameters, "dl=" + url);
            CollectionAssert.Contains(parameters, "dt=" + title);
            CollectionAssert.Contains(parameters, "cd=" + description);
            CollectionAssert.Contains(parameters, "dp=" + path);
            CollectionAssert.Contains(parameters, "dh=" + hostName);
        }
Ejemplo n.º 2
0
        public void MeasurementUriBuilderTests_BuildUri_Emits_SessionControl_start_At_Start()
        {
            var config  = MeasurementTestHelpers.Configuration;
            var builder = new MeasurementUriBuilder(config, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment());

            var actual = builder.BuildUri(new ScreenViewActivity("Home"));

            StringAssert.Contains(actual.Query, "sc=start");
        }
Ejemplo n.º 3
0
        public void MeasurementUriBuilderTests_BuildUri_Carries_Forward_Cd_Parameter()
        {
            var config  = MeasurementTestHelpers.Configuration;
            var builder = new MeasurementUriBuilder(config, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment());

            builder.BuildUri(new ScreenViewActivity("CarriedForward"));
            var actual = builder.BuildUri(new EventActivity("Action", "Category"));

            StringAssert.Contains(actual.Query, "cd=CarriedForward");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void MeasurementUriBuilderTests_BuildUri_Emits_SessionControl_end_At_End()
        {
            var config         = MeasurementTestHelpers.Configuration;
            var sessionManager = MeasurementTestHelpers.CreateSessionManager();
            var builder        = new MeasurementUriBuilder(config, sessionManager, MeasurementTestHelpers.CreateEnvironment());

            sessionManager.End();
            var actual = builder.BuildUri(new EventActivity("Action", "Category"));

            StringAssert.Contains(actual.Query, "sc=end");
        }
Ejemplo n.º 6
0
        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 MeasurementActivityEntry(new AppViewActivity("Testing")));

            Assert.AreEqual(0, actual.Count);
        }
        public void AppViewExtension_Tracks_AppView()
        {
            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackAppView("SomeScreenName");

            Assert.AreEqual(1, list.Count);
            StringAssert.Contains(list[0].OriginalString, "t=appview");
        }
Ejemplo n.º 8
0
        public void MeasurementUriBuilderTests_BuildUri_Is_https_And_ssl_When_Using_SSL()
        {
            var config = MeasurementTestHelpers.Configuration;

            config.UseSsl = true;
            var builder = new MeasurementUriBuilder(config, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment());

            var actual = builder.BuildUri(new ScreenViewActivity("Home"));

            Assert.AreEqual("https", actual.Scheme);
            Assert.AreEqual("ssl.google-analytics.com", actual.Host);
        }
        public void MeasurementUriBuilderTests_BuildUri_Is_http_And_www_When_Not_Using_SSL()
        {
            var config = MeasurementTestHelpers.Configuration;

            config.UseSsl = false;
            var builder = new MeasurementUriBuilder(config, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment());

            var actual = builder.BuildUri(new MeasurementActivityEntry(new AppViewActivity("Home")));

            Assert.AreEqual("http", actual.Scheme);
            Assert.AreEqual("www.google-analytics.com", actual.Host);
        }
Ejemplo n.º 10
0
        public void MeasurementUriBuilderTests_BuildUri_Emits_No_SessionControl_After_Start()
        {
            var config         = MeasurementTestHelpers.Configuration;
            var sessionManager = MeasurementTestHelpers.CreateSessionManager();
            var builder        = new MeasurementUriBuilder(config, sessionManager, MeasurementTestHelpers.CreateEnvironment());

            sessionManager.Hit();
            var actual = builder.BuildUri(new ScreenViewActivity("Page2"));

            var parameters = actual.Query.Split('&').Select(p => p.Split('=')).ToDictionary(k => k[0], v => v.Length == 0 ? null : v[1]);

            CollectionAssert.DoesNotContain(parameters.Keys, "sc");
        }
        public void MeasurementAnalyticsClient_Replays_Tracked_Activities_After_Configured()
        {
            var actual = new List <Uri>();

            var client = new MeasurementAnalyticsClient();

            client.Track(new ScreenViewActivity("The Big Screen"));
            client.Track(new ScreenViewActivity("Silk Screen"));

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            Assert.AreEqual(2, actual.Count);
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Decimal_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(8, 123456.78m);
            client.TrackAppView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm8=123456.78");
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Int_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(6, 6060);
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm6=6060");
        }
        public void MeasurementAnalyticsClient_SetCustomDimension_By_Enum_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomDimension(CustomDimensions.Eight, "DimensionEight");
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cd8=DimensionEight");
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Timespan_Is_Sent()
        {
            var actual         = new List <Uri>();
            var actualTimespan = new TimeSpan(4, 1, 2, 3);
            var client         = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(7, actualTimespan);
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm7=" + (int)actualTimespan.TotalSeconds);
        }
Ejemplo n.º 16
0
        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 MeasurementActivityEntry(new AppViewActivity("Testing"))
            {
                EndSession = true
            });

            Assert.AreEqual(SessionStatus.Ending, sessionManager.SessionStatus);
            StringAssert.Contains(actual.Last().OriginalString, "sc=end");
        }
Ejemplo n.º 17
0
        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 MeasurementActivityEntry(new AppViewActivity("OptedOut")));
            sessionManager.VisitorStatus = VisitorStatus.Active;
            tracker.Track(new MeasurementActivityEntry(new AppViewActivity("OptedIn")));

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].OriginalString, "cd=OptedIn");
        }
        public void MeasurementUriBuilderTests_TrackingEndpointOverride_IsUsed_DontCare_UseSsl()
        {
            var config = MeasurementTestHelpers.Configuration;

            config.UseSsl = false;
            var trackingEnpointOverride = new Uri("https://www.sonova-ga-analytics.com/collect");

            config.TrackingEndpointOverride = trackingEnpointOverride;
            var builder = new MeasurementUriBuilder(config, MeasurementTestHelpers.CreateSessionManager(), MeasurementTestHelpers.CreateEnvironment());

            var actual = builder.BuildUri(new ScreenViewActivity("Home"));

            Assert.AreEqual(trackingEnpointOverride.Host, actual.Host);
            Assert.AreEqual(trackingEnpointOverride.Scheme, actual.Scheme);
        }
        public void TrackException_Tracks_Exception()
        {
            const string description = "Some action";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackException(description);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=exception");
            CollectionAssert.Contains(parameters, "exd=" + description);
            CollectionAssert.Contains(parameters, "exf=0");
        }
        public void TrackSocial_Tracks_Social()
        {
            const string action  = "Poke";
            const string network = "FriendFace";
            const string target  = "Clown";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackSocial(action, network, target);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=social");
            CollectionAssert.Contains(parameters, "sa=" + action);
            CollectionAssert.Contains(parameters, "sn=" + network);
            CollectionAssert.Contains(parameters, "st=" + target);
        }
        public void TrackTimedEvent_Tracks_TimedEvent()
        {
            const string category = "A category";
            const string variable = "Some variable";
            var          time     = TimeSpan.FromMilliseconds(12345);
            const string label    = "Blue";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackTimedEvent(category, variable, time, label);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=timing");
            CollectionAssert.Contains(parameters, "utc=" + category);
            CollectionAssert.Contains(parameters, "utv=" + variable);
            CollectionAssert.Contains(parameters, "utt=" + time.TotalMilliseconds);
            CollectionAssert.Contains(parameters, "utl=" + label);
        }
        public void TrackEvent_Tracks_Event()
        {
            const string action   = "Some action";
            const string category = "Category Z";
            const string label    = "I am a label";
            const int    value    = 55;

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackEvent(action, category, label, value, true);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=event");
            CollectionAssert.Contains(parameters, "ea=" + action);
            CollectionAssert.Contains(parameters, "ec=" + category);
            CollectionAssert.Contains(parameters, "el=" + label);
            CollectionAssert.Contains(parameters, "ev=" + value);
            CollectionAssert.Contains(parameters, "ni=1");
        }
Ejemplo n.º 23
0
        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(new MeasurementActivityEntry(transaction));

            var transactionItem = new TransactionItemActivity("ABC", "Unit Test", 1.23m, 4);

            tracker.Track(new MeasurementActivityEntry(transactionItem));

            Assert.AreEqual(transaction, transactionItem.Transaction);
            StringAssert.Contains(actual.Last().OriginalString, "ti=123");
        }
Ejemplo n.º 24
0
        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);
        }