Configuration settings for analytics.
        public void MeasurementConfiguration_Constructor_With_Required_Parameters_Sets_Correct_Defaults()
        {
            var configuration = new MeasurementConfiguration("UA-1234-5", "ApplicationName", "1.2.3.4");

            Assert.IsTrue(configuration.AnonymizeIp);
            Assert.IsFalse(configuration.UseSsl);
        }
        /// <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 MeasurementUriBuilderTests_GetParameters_For_Configuration_Returns_Correct_Keys()
        {
            var configuration = new MeasurementConfiguration("UA-1234-5", "AppName", "1.2.3.4");

            var keys = MeasurementUriBuilder.GetParameters(configuration).Select(k => k.Key).ToArray();

            CollectionAssert.AreEquivalent(new[] { "tid", "an", "av", "aip" }, keys);
        }
        public void MeasurementUriBuilderTests_GetParameters_For_Configuration_Returns_No_Aip_Value_When_False()
        {
            var configuration = new MeasurementConfiguration("UA-1234-5", "AppName", "1.2.3.4") { AnonymizeIp = false };

            var keys = MeasurementUriBuilder.GetParameters(configuration).Select(k => k.Key).ToArray();

            CollectionAssert.DoesNotContain(keys, "aip");
        }
        public void MeasurementConfiguration_Constructor_With_Required_Parameters_Sets_Correct_Properties()
        {
            var configuration = new MeasurementConfiguration("UA-1234-5", "ApplicationName", "1.2.3.4");

            Assert.AreEqual("UA-1234-5", configuration.AccountId);
            Assert.AreEqual("ApplicationName", configuration.ApplicationName);
            Assert.AreEqual("1.2.3.4", configuration.ApplicationVersion);
        }
        public void MeasurementConfiguration_SampleRate_Property_Can_Be_Set()
        {
            var expected = 51.2;
            var configuration = new MeasurementConfiguration("UA-1234-5", "ApplicationName", "1.2.3.4") {
                SampleRate = expected
            };

            Assert.AreEqual(expected, configuration.SampleRate);
        }
        /// <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;
        }
        /// <summary>
        /// Get parameters for a given configuration.
        /// </summary>
        /// <param name="configuration">Configuration to obtain parameters from.</param>
        /// <returns>Enumerable of key/value pairs containing parameters for this configuration.</returns>
        internal static IEnumerable <KeyValuePair <string, string> > GetParameters(MeasurementConfiguration configuration)
        {
            yield return(KeyValuePair.Create("tid", configuration.AccountId));

            yield return(KeyValuePair.Create("an", configuration.ApplicationName));

            yield return(KeyValuePair.Create("av", configuration.ApplicationVersion));

            if (configuration.AnonymizeIp)
            {
                yield return(KeyValuePair.Create("aip", "1"));
            }
        }
Esempio n. 10
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();
        }
 /// <summary>
 /// Create new MeasurementUriBuilder to prepare URIs for Google's Measurement Protocol endpoint.
 /// </summary>
 /// <param name="configuration">Configuration of analytics.</param>
 /// <param name="sessionManager">Session manager.</param>
 /// <param name="environment">Environment details.</param>
 public MeasurementUriBuilder(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment)
 {
     this.configuration  = configuration;
     this.sessionManager = sessionManager;
     this.environment    = environment;
 }
 /// <summary>
 /// Create new MeasurementUriBuilder to prepare URIs for Google's Measurement Protocol endpoint.
 /// </summary>
 /// <param name="configuration">Configuration of analytics.</param>
 /// <param name="sessionManager">Session manager.</param>
 /// <param name="environment">Environment details.</param>
 public MeasurementUriBuilder(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment)
 {
     this.configuration = configuration;
     this.sessionManager = sessionManager;
     this.environment = environment;
 }
        /// <summary>
        /// Get parameters for a given configuration.
        /// </summary>
        /// <param name="configuration">Configuration to obtain parameters from.</param>
        /// <returns>Enumerable of key/value pairs containing parameters for this configuration.</returns>
        internal static IEnumerable<KeyValuePair<string, string>> GetParameters(MeasurementConfiguration configuration)
        {
            yield return KeyValuePair.Create("tid", configuration.AccountId);
            yield return KeyValuePair.Create("an", configuration.ApplicationName);
            yield return KeyValuePair.Create("av", configuration.ApplicationVersion);

            if (configuration.AnonymizeIp)
                yield return KeyValuePair.Create("aip", "1");
        }
Esempio n. 14
0
 /// <summary>
 /// Create a new MeasurementTracker 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 MeasurementTracker(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment, Action <Uri> sender)
 {
     this.sessionManager = sessionManager;
     this.sender         = sender;
     uriBuilder          = new MeasurementUriBuilder(configuration, sessionManager, environment);
 }
Esempio n. 15
0
 /// <summary>
 /// Create a new MeasurementTracker 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 MeasurementTracker(MeasurementConfiguration configuration, SessionManager sessionManager, IEnvironment environment, Action<Uri> sender)
 {
     this.sessionManager = sessionManager;
     this.sender = sender;
     uriBuilder = new MeasurementUriBuilder(configuration, sessionManager, environment);
 }
 public void CustomVariable_Constructor_Throws_ArgumentOutOfRange_If_Enum_Undefined()
 {
     var configuration = new MeasurementConfiguration("NO-1234-5", "ApplicationName", "1.2.3.4");
 }
 public void MeasurementConfiguration_SampleRate_Property_Throws_ArgumentOutOfRangeException_If_Below_0()
 {
     var configuration = new MeasurementConfiguration("UA-1234-5", "ApplicationName", "1.2.3.4");
     Assert.ThrowsException<ArgumentOutOfRangeException>(() => configuration.SampleRate = -0.01);
 }
 public void MeasurementConfiguration_SampleRate_Property_Throws_ArgumentOutOfRangeException_If_Above_100()
 {
     var configuration = new MeasurementConfiguration("UA-1234-5", "ApplicationName", "1.2.3.4");
     configuration.SampleRate = 100.01;
 }
 public void MeasurementConfiguration_Constructor_Throws_ArgumentException_If_AccountID_Does_Not_Have_Two_Numeric_Parts()
 {
     var configuration = new MeasurementConfiguration("UA-1234", "ApplicationName", "1.2.3.4");
 }