Esempio n. 1
0
        /// <summary>
        /// Start CSharpAnalytics by restoring the session state, starting the background sender,
        /// hooking up events to track and firing the application start event and home page view to analytics.
        /// Call this just before Window.Current.Activate() in your App.OnLaunched method.
        /// </summary>
        /// <param name="configuration">Configuration to use, must at a minimum specify your Google Analytics ID and app name.</param>
        /// <param name="uploadInterval">How often to upload to the server. Lower times = more traffic but realtime. Defaults to 5 seconds.</param>
        /// <returns>A Task that will complete once CSharpAnalytics is available.</returns>
        /// <example>await AutoAnalytics.StartAsync(new Configuration("UA-123123123-1", "myapp.someco.com"));</example>
        public static async Task StartAsync(MeasurementConfiguration configuration, TimeSpan? uploadInterval = null)
        {
            Debug.Assert(Client == null);
            if (Client != null) return;

            await StartRequesterAsync(uploadInterval ?? TimeSpan.FromSeconds(5));
            await RestoreSessionAsync(TimeSpan.FromMinutes(20));

            Client = new MeasurementAnalyticsClient(configuration, sessionManager, new WindowsStoreEnvironment(), requester.Add);
            Client.TrackEvent("Start", "ApplicationLifecycle");
            Client.TrackAppView("Home");

            HookEvents();
        }
        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");
        }