public void UrchinTracker_GetFinalCustomVariables_Selects_Correct_Final_Variables()
        {
            var sessionScopedVariables = new ScopedCustomVariableSlots(CustomVariableScope.Session);
            sessionScopedVariables[0] = new CustomVariable("session-one-name", "session-one-value");
            sessionScopedVariables[2] = new CustomVariable("session-three-name", "session-three-value");

            var visitorScopedVariables = new ScopedCustomVariableSlots(CustomVariableScope.Visitor);
            visitorScopedVariables[0] = new CustomVariable("Visitor-one-name", "Visitor-one-value");
            visitorScopedVariables[1] = new CustomVariable("Visitor-two-name", "Visitor-two-value");

            var activityScopedVariables = new ScopedCustomVariableSlots(CustomVariableScope.Activity);
            activityScopedVariables[0] = new CustomVariable("activity-one-name", "activity-one-value");
            activityScopedVariables[1] = new CustomVariable("activity-two-name", "activity-two-value");
            activityScopedVariables[3] = new CustomVariable("activity-four-name", "activity-four-value");

            var final = UrchinTracker.GetFinalCustomVariables(sessionScopedVariables, visitorScopedVariables, activityScopedVariables);

            Assert.AreEqual(CustomVariableScope.Visitor, final[0].Scope);
            Assert.AreEqual(CustomVariableScope.Visitor, final[1].Scope);
            Assert.AreEqual(CustomVariableScope.Session, final[2].Scope);
            Assert.AreEqual(CustomVariableScope.Activity, final[3].Scope);

            Assert.AreEqual("Visitor-one-name", final[0].Variable.Name);
            Assert.AreEqual("Visitor-two-name", final[1].Variable.Name);
            Assert.AreEqual("session-three-name", final[2].Variable.Name);
            Assert.AreEqual("activity-four-name", final[3].Variable.Name);

            Assert.AreEqual(3, final.GetUpperBound(0));
        }
        public void ScopedCustomVariableSlots_Are_Scoped()
        {
            var sessionSlots = new ScopedCustomVariableSlots(CustomVariableScope.Session);
            var activitySlots = new ScopedCustomVariableSlots(CustomVariableScope.Activity);

            Assert.AreEqual(CustomVariableScope.Session, sessionSlots.Scope);
            Assert.AreEqual(CustomVariableScope.Activity, activitySlots.Scope);
        }
        public void ScopedCustomVariable_Constructor_Sets_Properties()
        {
            const CustomVariableScope scope = CustomVariableScope.Session;
            var scopedCustomVariableSlots = new ScopedCustomVariableSlots(scope);

            Assert.AreEqual(scope, scopedCustomVariableSlots.Scope);
            Assert.AreEqual(0, scopedCustomVariableSlots.AllSlots.Count());
        }
Пример #4
0
        /// <summary>
        /// Create an Urchin style URI from an activity and custom variables.
        /// </summary>
        /// <param name="activity">Activity to create a URI for.</param>
        /// <param name="customVariables">Custom variables to include in the URI.</param>
        /// <returns>Uri that when requested will track this activity.</returns>
        public Uri CreateUri(IUrchinActivity activity, ScopedCustomVariableSlots[] customVariables)
        {
            var parameters = BuildParameterList(activity, customVariables);

            CarryForwardLastPageParameter(activity, parameters);

            var uriBuilder = new UriBuilder(configuration.UseSsl ? secureTrackingEndpoint : trackingEndpoint) { Query = CreateQueryString(parameters) };
            return uriBuilder.Uri;
        }
        public void ScopedCustomVariableSlots_Slots_Are_Initially_Empty()
        {
            var slots = new ScopedCustomVariableSlots(CustomVariableScope.Session);

            Assert.IsNull(slots[0]);
            Assert.IsNull(slots[1]);
            Assert.IsNull(slots[2]);
            Assert.IsNull(slots[3]);
            Assert.IsNull(slots[4]);
        }
Пример #6
0
        /// <summary>
        /// Create an Urchin style URI from an activity and custom variables.
        /// </summary>
        /// <param name="activity">Activity to create a URI for.</param>
        /// <param name="customVariables">Custom variables to include in the URI.</param>
        /// <returns>Uri that when requested will track this activity.</returns>
        public Uri CreateUri(IActivity activity, ScopedCustomVariableSlots[] customVariables)
        {
            var parameters = BuildParameterList(activity, customVariables);

            // Undocumented parameter to set the date/time event occured - useful for offline or batch modes
            if (configuration.SendClientTime)
                parameters.Add(KeyValuePair.Create("utmht", new EpochTime(DateTimeOffset.Now).ToString()));

            CarryForwardLastPageParameter(activity, parameters);

            var uriBuilder = new UriBuilder(configuration.UseSsl ? secureTrackingEndpoint : trackingEndpoint) { Query = CreateQueryString(parameters) };
            return uriBuilder.Uri;
        }
        /// <summary>
        /// Track this activity in analytics.
        /// </summary>
        /// <param name="activity">Activity to track in analytics.</param>
        /// <param name="activityCustomVariables">Activity scoped custom variable slots to record for this activity.</param>
        public void Track(IUrchinActivity activity, ScopedCustomVariableSlots activityCustomVariables = null)
        {
            if (activityCustomVariables != null && activityCustomVariables.Scope != CustomVariableScope.Activity)
                throw new ArgumentException("Custom variable slots must be scoped to activity", "activityCustomVariables");

            if (activity is AutoTimedEventActivity)
                ((AutoTimedEventActivity)activity).End();

            sessionManager.Hit();
            var trackingUri = tracker.CreateUri(activity, new[] { VisitorCustomVariables, SessionCustomVariables, activityCustomVariables });
            sender(trackingUri);

            if (activity is PageViewActivity)
                sessionManager.Referrer = new Uri("http://" + hostName + ((PageViewActivity)activity).Page);
        }
        public void ScopedCustomVariableSlots_Slots_Can_Be_Set()
        {
            var slotOne = new CustomVariable("one", "1");
            var slotTwo = new CustomVariable("two", "2");
            var slotThree = new CustomVariable("three", "3");
            var slotFour = new CustomVariable("four", "4");
            var slotFive = new CustomVariable("five", "5");

            var slots = new ScopedCustomVariableSlots(CustomVariableScope.Session);
            slots[0] = slotOne;
            slots[1] = slotTwo;
            slots[2] = slotThree;
            slots[3] = slotFour;
            slots[4] = slotFive;

            Assert.AreSame(slotOne, slots[0]);
            Assert.AreSame(slotTwo, slots[1]);
            Assert.AreSame(slotThree, slots[2]);
            Assert.AreSame(slotFour, slots[3]);
            Assert.AreSame(slotFive, slots[4]);
        }
        public void ScopedCustomVariable_Slot_Properties_Can_Be_Set()
        {
            var scopedCustomVariableSlots = new ScopedCustomVariableSlots(CustomVariableScope.Session);
            var slot1 = new CustomVariable("name1", "value1");
            var slot2 = new CustomVariable("name2", "value2");
            var slot3 = new CustomVariable("name3", "value3");
            var slot4 = new CustomVariable("name4", "value4");
            var slot5 = new CustomVariable("name5", "value5");

            scopedCustomVariableSlots[0] = slot1;
            scopedCustomVariableSlots[1] = slot2;
            scopedCustomVariableSlots[2] = slot3;
            scopedCustomVariableSlots[3] = slot4;
            scopedCustomVariableSlots[4] = slot5;

            Assert.AreSame(slot1, scopedCustomVariableSlots[0]);
            Assert.AreSame(slot2, scopedCustomVariableSlots[1]);
            Assert.AreSame(slot3, scopedCustomVariableSlots[2]);
            Assert.AreSame(slot4, scopedCustomVariableSlots[3]);
            Assert.AreSame(slot5, scopedCustomVariableSlots[4]);
        }
Пример #10
0
        /// <summary>
        /// Build a list of the parameters required based on configuration, environment, activity, session, custom variables and state.
        /// </summary>
        /// <param name="activity">Activity to include in the parameter list.</param>
        /// <param name="customVariables">Custom variables to include in the parameter list.</param>
        /// <returns>List of key/value pairs containing the parameters necessary for this request.</returns>
        private List<KeyValuePair<string, string>> BuildParameterList(IActivity activity, ScopedCustomVariableSlots[] customVariables)
        {
            var finalCustomVariables = GetFinalCustomVariables(customVariables);

            return GetParameters()
                .Concat(GetParameters(environment))
                .Concat(GetParameters(configuration))
                .Concat(GetParameters(sessionManager, configuration.GetHostNameHash()))
                .Concat(GetParameters(finalCustomVariables))
                .Concat(UrchinTrackerActivities.GetActivityParameters(activity))
                .ToList();
        }
 public void CustomVariable_Constructor_Throws_ArgumentOutOfRange_If_Scope_Is_None()
 {
     var scoped = new ScopedCustomVariableSlots(CustomVariableScope.None);
 }
 public void CustomVariable_Constructor_Throws_ArgumentOutOfRange_If_Enum_Undefined()
 {
     var scoped = new ScopedCustomVariableSlots((CustomVariableScope) 1234);
 }