Inheritance: IMeasurementActivity
 internal static IEnumerable<KeyValuePair<string, string>> GetParameters(EventActivity @event)
 {
     yield return KeyValuePair.Create("utmt", "event");
     yield return KeyValuePair.Create("utme", ToEventParameter(@event));
     if (@event.NonInteraction)
         yield return KeyValuePair.Create("utmi", "1");
 }
        public void UrchinActivityTracker_GetParameter_For_EventActivity_Returns_Correctly_Encoded_Utme_Value()
        {
            var activity = new EventActivity("*)!", "a*b)c!d'2", label: "*", value: 1);

            var actual = UrchinActivityTracker.GetParameters(activity).First(f => f.Key == "utme").Value;

            Assert.AreEqual("5(a'2b'1c'3d'02*'2'1'3*'2)(1)", actual);
        }
Exemplo n.º 3
0
        public void EventActivity_Constructor_With_All_Parameters_Sets_Correct_Properties()
        {
            var activity = new EventActivity("action", "category", label: "label", value: 5);

            Assert.AreEqual("category", activity.Category);
            Assert.AreEqual("action", activity.Action);
            Assert.AreEqual("label", activity.Label);
            Assert.AreEqual(5, activity.Value);
        }
Exemplo n.º 4
0
        public void EventActivity_Constructor_With_Minimal_Parameters_Sets_Correct_Properties()
        {
            var activity = new EventActivity("action", "category");

            Assert.AreEqual("category", activity.Category);
            Assert.AreEqual("action", activity.Action);

            Assert.IsNull(activity.Label);
            Assert.IsNull(activity.Value);
            Assert.IsFalse(activity.NonInteraction);
        }
        public void MeasurementActivityTracker_GetParameter_For_EventActivity_Returns_Correct_Values()
        {
            var activity = new EventActivity("action", "category", "label", 123, true);

            var parameters = MeasurementActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v.Value);

            Assert.AreEqual(6, parameters.Keys.Count);
            Assert.AreEqual("event", parameters["t"]);
            Assert.AreEqual("action", parameters["ea"]);
            Assert.AreEqual("category", parameters["ec"]);
            Assert.AreEqual("label", parameters["el"]);
            Assert.AreEqual("123", parameters["ev"]);
            Assert.AreEqual("1", parameters["ni"]);
        }
        public void UrchinTracker_CreateCookieSubstituteParameter()
        {
            var @event = new EventActivity("action", "catgory", "label", 123, true);
            var sessionState = new SessionState
                {
                    SessionNumber = 5,
                    VisitorId = new Guid("FFFCCBCB-9A87-4987-BD20-CE7C81F96CD2"),
                    FirstVisitAt = new DateTimeOffset(2012, 10, 10, 13, 14, 15, TimeSpan.Zero),
                    PreviousSessionStartedAt = new DateTimeOffset(2012, 12, 10, 13, 14, 15, TimeSpan.Zero),
                    SessionStartedAt = new DateTimeOffset(2012, 12, 14, 13, 14, 15, TimeSpan.Zero),
                };
            var sessionManager = new SessionManager(TimeSpan.FromMinutes(5), sessionState);

            var cookieSubstitute = UrchinTracker.CreateCookieSubstituteParameter(sessionManager, 1);

            Assert.AreEqual("__utma=1.1159017511.1349874855.1355145255.1355490855.5;", cookieSubstitute);
        }
        private static string ToEventParameter(EventActivity @event)
        {
            var queryValue = UtmeEncoder.Encode("5", @event.Category, @event.Action, @event.Label);
            if (@event.Value.HasValue)
                queryValue += "(" + UtmeEncoder.EscapeValue(@event.Value.Value.ToString(CultureInfo.InvariantCulture)) + ")";

            return queryValue;
        }
        /// <summary>
        /// Obtain the key/value pairs for an EventActivity.
        /// </summary>
        /// <param name="event">EventActivity to turn into key/value pairs.</param>
        /// <returns>Key/value pairs representing this EventActivity.</returns>
        internal static IEnumerable<KeyValuePair<string, string>> GetParameters(EventActivity @event)
        {
            yield return KeyValuePair.Create("t", "event");

            foreach (var parameter in GetCommonParameters(@event))
                yield return parameter;

            if (!String.IsNullOrWhiteSpace(@event.Category))
                yield return KeyValuePair.Create("ec", @event.Category);

            if (!String.IsNullOrWhiteSpace(@event.Action))
                yield return KeyValuePair.Create("ea", @event.Action);

            if (!String.IsNullOrWhiteSpace(@event.Label))
                yield return KeyValuePair.Create("el", @event.Label);

            if (@event.Value.HasValue)
                yield return KeyValuePair.Create("ev", @event.Value.Value.ToString(CultureInfo.InvariantCulture));
        }
        public void UrchinActivityTracker_GetParameter_For_EventActivity_Returns_Correct_Utmt_Value()
        {
            var activity = new EventActivity("action", "category");

            var results = UrchinActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v);

            CollectionAssert.Contains(results.Keys, "utmt");
            Assert.AreEqual("event", results["utmt"].Value);
        }
        public void UrchinActivityTracker_GetParameter_For_EventActivity_Returns_Correct_Keys()
        {
            var activity = new EventActivity("action", "category", nonInteraction: true);

            var results = UrchinActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v);

            var expectedKeys = new[] { "utmt", "utme", "utmi" };
            CollectionAssert.AreEquivalent(expectedKeys, results.Keys);
        }
        public void UrchinActivityTracker_GetParameter_For_EventActivity_With_Two_Parameters_Returns_Correct_Utme_Value()
        {
            var activity = new EventActivity("action", "category");

            var actual = UrchinActivityTracker.GetParameters(activity).First(f => f.Key == "utme").Value;

            Assert.AreEqual("5(category*action)", actual);
        }
        public void UrchinActivityParameterBuilder_GetParameter_For_EventActivity_With_Four_Parameters_Returns_Correct_Utme_Value()
        {
            var activity = new EventActivity("action", "category", label: "label", value: 1234);

            var actual = UrchinActivityParameterBuilder.GetParameters(activity).First(f => f.Key == "utme").Value;

            Assert.AreEqual("5(category*action*label)(1234)", actual);
        }