public void UrchinUriBuilder_GetFinalCustomVariables_Selects_Correct_Final_Variables() { var analyticsClient = new UrchinAnalyticsClient(); analyticsClient.SessionCustomVariables[0] = new CustomVariable("session-one-name", "session-one-value"); analyticsClient.SessionCustomVariables[2] = new CustomVariable("session-three-name", "session-three-value"); analyticsClient.VisitorCustomVariables[0] = new CustomVariable("Visitor-one-name", "Visitor-one-value"); analyticsClient.VisitorCustomVariables[1] = new CustomVariable("Visitor-two-name", "Visitor-two-value"); var activityScopedVariables = new CustomVariableSlots(); 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 = analyticsClient.GetFinalCustomVariables(activityScopedVariables).ToDictionary(s => s.Slot); 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); }
public void CustomVariableSlots_Indexer_Sets_Slot() { var slots = new CustomVariableSlots(); var slotOne = new CustomVariable("one", "1"); slots[1] = slotOne; Assert.AreEqual(slotOne, slots[1]); }
public void CustomVariableSlots_Indexer_Overwrites_Slot_When_Set_Again() { var slots = new CustomVariableSlots(); var slotOneA = new CustomVariable("oneA", "1A"); var slotOneB = new CustomVariable("oneB", "1B"); slots[1] = slotOneA; slots[1] = slotOneB; Assert.AreEqual(1, slots.AllSlots.Count()); Assert.AreEqual(slotOneB, slots[1]); }
public void CustomVariableSlots_AllSlots_Identifies_By_Key() { var slots = new CustomVariableSlots(); var slotOne = new CustomVariable("one", "1"); var slotSix = new CustomVariable("six", "6"); slots[1] = slotOne; slots[6] = slotSix; Assert.AreEqual(slotOne, slots.AllSlots.First(s => s.Key == 1).Value); Assert.AreEqual(slotSix, slots.AllSlots.First(s => s.Key == 6).Value); }
public void CustomVariableSlots_Indexer_Sets_Multiple_Slot() { var slots = new CustomVariableSlots(); var slotOne = new CustomVariable("one", "1"); var slotNine = new CustomVariable("nine", "9"); slots[1] = slotOne; slots[9] = slotNine; Assert.AreEqual(2, slots.AllSlots.Count()); Assert.AreEqual(slotOne, slots[1]); Assert.AreEqual(slotNine, slots[9]); }
public void CustomVariableSlots_Indexer_Unsets_Slot_When_Set_To_Null() { var slots = new CustomVariableSlots(); var slotOne = new CustomVariable("one", "1"); var slotNine = new CustomVariable("nine", "9"); slots[1] = slotOne; slots[9] = slotNine; slots[9] = null; Assert.AreEqual(1, slots.AllSlots.Count()); Assert.AreEqual(slotOne, slots[1]); Assert.IsNull(slots[9]); }
/// <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, CustomVariableSlots activityCustomVariables = null) { if (activity is AutoTimedEventActivity) ((AutoTimedEventActivity)activity).End(); var entry = new UrchinActivityEntry { Activity = activity, CustomVariables = GetFinalCustomVariables(activityCustomVariables) }; if (tracker == null) queue.Enqueue(entry); else tracker.Track(entry); }
/// <summary> /// Expands a set of scoped custom variable slots into a final array containing the custom variables and their scope. /// </summary> /// <param name="activityCustomVariables">Set of scoped custom variable slots to expand.</param> /// <returns>An array of custom variables with their scope indexed by slot.</returns> internal ScopedCustomVariableSlot[] GetFinalCustomVariables(CustomVariableSlots activityCustomVariables) { var finalSlots = new Dictionary<int, ScopedCustomVariableSlot>(); if (activityCustomVariables != null) foreach (var slot in activityCustomVariables.AllSlots) finalSlots[slot.Key] = new ScopedCustomVariableSlot(CustomVariableScope.Activity, slot.Value, slot.Key); foreach (var slot in SessionCustomVariables.AllSlots) finalSlots[slot.Key] = new ScopedCustomVariableSlot(CustomVariableScope.Session, slot.Value, slot.Key); foreach (var slot in VisitorCustomVariables.AllSlots) finalSlots[slot.Key] = new ScopedCustomVariableSlot(CustomVariableScope.Visitor, slot.Value, slot.Key); return finalSlots.Values.ToArray(); }