示例#1
0
        //Service start
        public static void Start(DynamoModel dynamoModel)
        {
            InstrumentationLogger.dynamoModel = dynamoModel;

            if (IsAnalyticsEnabled)
            {
                string appVersion = dynamoModel.AppVersion;

                var mc = new MeasurementConfiguration(ANALYTICS_PROPERTY,
                    "Dynamo", appVersion);
                mc.AnonymizeIp = true;

                sessionID = Guid.NewGuid().ToString();
                loggerImpl = new Log("Dynamo", userID, sessionID);
            
                AutoMeasurement.Start(mc);
                client = AutoMeasurement.Client;

                if (IS_VERBOSE_DIAGNOSTICS)
                    AutoMeasurement.DebugWriter = d => Debug.WriteLine(d);

                started = true;
            }


            // The following starts the heartbeat, do not remove this 
            // because of the unreferenced "heartbeat" variable.

// ReSharper disable UnusedVariable
            var heartbeat = Heartbeat.GetInstance(dynamoModel);
// ReSharper restore UnusedVariable

        }
示例#2
0
文件: Logger.cs 项目: whztt07/Dynamo
        //Service start
        public static void Start(DynamoModel dynamoModel)
        {
            string appVersion = Process.GetCurrentProcess().ProcessName + "-"
                                + UpdateManager.UpdateManager.Instance.ProductVersion.ToString();


            CSharpAnalytics.MeasurementConfiguration mc = new MeasurementConfiguration(ANALYTICS_PROPERTY,
                "Dynamo", appVersion);

            sessionID = Guid.NewGuid().ToString();
            loggerImpl = new Log("Dynamo", userID, sessionID);

            
            CSharpAnalytics.AutoMeasurement.Start(mc);
            client = AutoMeasurement.Client;

            if (IS_VERBOSE_DIAGNOSTICS)
            {
                AutoMeasurement.DebugWriter = d => Debug.WriteLine(d);
            }

            started = true;

            // The following starts the heartbeat, do not remove this 
            // because of the unreferenced "heartbeat" variable.

// ReSharper disable UnusedVariable
            var heartbeat = Heartbeat.GetInstance(dynamoModel);
// ReSharper restore UnusedVariable

        }
        public void MeasurementAnalyticsClient_AdjustUriBeforeRequest_Adds_Qt_Parameter()
        {
            var originalUri = new Uri("http://anything.really.com/something#" + DateTime.UtcNow.ToString("o"));

            var actual = new MeasurementAnalyticsClient().AdjustUriBeforeRequest(originalUri);

            StringAssert.Contains(actual.Query, "qt=");
        }
        public void MeasurementAnalyticsClient_AdjustUriBeforeRequest_Clears_Fragment()
        {
            var originalUri = new Uri("http://anything.really.com/something#" + DateTime.UtcNow.ToString("o"));

            var actual = new MeasurementAnalyticsClient().AdjustUriBeforeRequest(originalUri);

            Assert.AreEqual(actual.Fragment, "");
        }
        public void MeasurementAnalyticsClient_Track_Ends_AutoTimedEventActivity()
        {
            var client = new MeasurementAnalyticsClient();
            var autoTimedEvent = new AutoTimedEventActivity("Category", "Variable");

            client.Track(autoTimedEvent);

            Assert.IsNotNull(autoTimedEvent.EndedAt);
        }
        public void MeasurementAnalyticsClient_OnTrack_Fires_When_Tracked()
        {
            var fired = false;
            var analyticsClient = new MeasurementAnalyticsClient();

            analyticsClient.OnTrack += (s, e) => fired = true;
            analyticsClient.Track(new AppViewActivity("Testing"));

            Assert.IsTrue(fired);
        }
        public void MeasurementAnalyticsClient_OnTrack_Fires_After_AutoTimedEvent_Ended()
        {
            DateTimeOffset? endedAt = null;
            var analyticsClient = new MeasurementAnalyticsClient();
            var autoTimedEvent = new AutoTimedEventActivity("Category", "Variable");

            analyticsClient.OnTrack += (s, e) => { endedAt = ((AutoTimedEventActivity) e).EndedAt; };
            analyticsClient.Track(autoTimedEvent);

            Assert.IsNotNull(endedAt);
        }
        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");
        }
        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_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);
        }
示例#12
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 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");
        }
示例#14
0
        /// <summary>
        /// Stop CSharpAnalytics by firing the analytics event, unhooking events and saving the session
        /// state and pending queue.
        /// Call this in your App.OnSuspending just before deferral.Complete(); 
        /// </summary>
        /// <returns>A Task that will complete once CSharpAnalytics is available.</returns>
        /// <remarks>await AutoAnalytics.StopAsync();</remarks>
        public static async Task StopAsync()
        {
            Debug.Assert(Client != null);
            if (Client == null) return;

            Client.TrackEvent("Stop", "ApplicationLifecycle");
            UnhookEvents();

            await SuspendRequesterAsync();
            await SaveSessionAsync();

            Client = null;
        }
        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);
        }
        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);
        }
示例#17
0
 public static void ConfigureForTest(MeasurementAnalyticsClient client, Action<Uri> sender)
 {
     client.Configure(Configuration, CreateSessionManager(), CreateEnvironment(), sender);
 }
        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");
        }
        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);
        }
        public void MeasurementAnalyticsClient_AdjustUriBeforeRequest_Does_Not_Add_Qt_Parameter_If_Sc_Parameter_Present()
        {
            var originalUri = new Uri("http://anything.really.com/something?sc=start#" + DateTime.UtcNow.ToString("o"));

            var actual = new MeasurementAnalyticsClient().AdjustUriBeforeRequest(originalUri);

            Assert.IsFalse(actual.Query.Contains("qt="));
        }
        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 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");
        }