/// <summary>
        /// Adds the tracker payload to the emitter.
        /// </summary>
        /// <param name="payload">The base event payload.</param>
        /// <param name="contexts">The list of contexts from the event.</param>
        private void AddTrackerPayload(TrackerPayload payload, List <IContext> contexts, string eventId)
        {
            // Add default parameters to the payload
            payload.Add(Constants.PLATFORM, this.platform.Value);
            payload.Add(Constants.APP_ID, this.appId);
            payload.Add(Constants.NAMESPACE, this.trackerNamespace);
            payload.Add(Constants.TRACKER_VERSION, Version.VERSION);

            // Add the subject data if available
            if (subject != null)
            {
                payload.AddDict(subject.GetPayload().GetDictionary());
            }

            // Add the session context if available
            if (session != null)
            {
                contexts.Add(session.GetSessionContext(eventId));
            }

            // Build the final context and add it to the payload
            if (contexts != null && contexts.Count > 0)
            {
                SelfDescribingJson envelope = GetFinalContext(contexts);
                payload.AddJson(envelope.GetDictionary(), this.base64Encoded, Constants.CONTEXT_ENCODED, Constants.CONTEXT);
            }

            Log.Verbose("Tracker: Sending event to the emitter.");
            Log.Verbose(" + Event: " + payload.ToString());

            // Add the event to the emitter.
            emitter.Add(payload);
        }
Exemple #2
0
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.SV_NAME, this.name);
            payload.Add(Constants.SV_ID, this.id);
            return(new SelfDescribingJson(Constants.SCHEMA_SCREEN_VIEW, payload.GetDictionary()));
        }
Exemple #3
0
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.EVENT, Constants.EVENT_PAGE_VIEW);
            payload.Add(Constants.PAGE_URL, pageUrl);
            payload.Add(Constants.PAGE_TITLE, pageTitle);
            payload.Add(Constants.PAGE_REFR, referrer);
            return(AddDefaultPairs(payload));
        }
        public void TestAddFunction()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add("demo", "application");

            Assert.AreEqual(1, payload.GetDictionary().Count);
            Assert.AreEqual("application", payload.GetDictionary()["demo"]);

            payload.Add("demo", null);
            Assert.AreEqual(1, payload.GetDictionary().Count);
            payload.Add(null, "demo");
            Assert.AreEqual(1, payload.GetDictionary().Count);
        }
Exemple #5
0
        public void TestEventStoreFunctions()
        {
            EventStore es = new EventStore();

            Assert.AreEqual(0, es.GetEventCount());

            TrackerPayload payload = new TrackerPayload();

            payload.Add("hello", "world");

            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.AreEqual(4, es.GetEventCount());
            Assert.IsTrue(es.DeleteEvent(4));
            Assert.AreEqual(3, es.GetEventCount());
            Assert.IsTrue(es.DeleteEvents(new List <int> {
                3, 2
            }));
            Assert.AreEqual(1, es.GetEventCount());
            Assert.IsTrue(es.DeleteAllEvents());
            Assert.AreEqual(0, es.GetEventCount());

            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.IsTrue(es.AddEvent(payload));
            Assert.AreEqual(4, es.GetEventCount());
            Assert.AreEqual(4, es.GetAllEvents().Count);
            Assert.AreEqual(2, es.GetDescEventRange(2).Count);
            Assert.AreEqual(payload.GetDictionary(), es.GetEvent(1).GetPayload().GetDictionary());

            Assert.IsTrue(es.DeleteAllEvents());
        }
Exemple #6
0
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.EVENT, Constants.EVENT_ECOMM);
            payload.Add(Constants.TR_ID, this.orderId);
            payload.Add(Constants.TR_TOTAL, string.Format("{0:0.00}", this.totalValue));
            payload.Add(Constants.TR_AFFILIATION, this.affiliation);
            payload.Add(Constants.TR_TAX, this.taxValueSet ? (string.Format("{0:0.00}", this.taxValue)) : null);
            payload.Add(Constants.TR_SHIPPING, this.shippingSet ? (string.Format("{0:0.00}", this.shipping)) : null);
            payload.Add(Constants.TR_CITY, this.city);
            payload.Add(Constants.TR_STATE, this.state);
            payload.Add(Constants.TR_COUNTRY, this.country);
            payload.Add(Constants.TR_CURRENCY, this.currency);
            return(AddDefaultPairs(payload));
        }
Exemple #7
0
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.EVENT, Constants.EVENT_UNSTRUCTURED);
            SelfDescribingJson envelope = new SelfDescribingJson(Constants.SCHEMA_UNSTRUCT_EVENT, this.eventData.GetDictionary());

            payload.AddJson(envelope.GetDictionary(), this.base64Encode, Constants.UNSTRUCTURED_ENCODED, Constants.UNSTRUCTURED);
            return(AddDefaultPairs(payload));
        }
Exemple #8
0
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.EVENT, Constants.EVENT_ECOMM_ITEM);
            payload.Add(Constants.TI_ITEM_ID, this.itemId);
            payload.Add(Constants.TI_ITEM_SKU, this.sku);
            payload.Add(Constants.TI_ITEM_NAME, this.name);
            payload.Add(Constants.TI_ITEM_CATEGORY, this.category);
            payload.Add(Constants.TI_ITEM_PRICE, string.Format("{0:0.00}", this.price));
            payload.Add(Constants.TI_ITEM_QUANTITY, this.quantity.ToString());
            payload.Add(Constants.TI_ITEM_CURRENCY, this.currency);
            return(AddDefaultPairs(payload));
        }
        // --- Interface Methods

        /// <summary>
        /// Gets the event payload.
        /// </summary>
        /// <returns>The event payload</returns>
        public override IPayload GetPayload()
        {
            TrackerPayload payload = new TrackerPayload();

            payload.Add(Constants.EVENT, Constants.EVENT_STRUCTURED);
            payload.Add(Constants.SE_CATEGORY, this.category);
            payload.Add(Constants.SE_ACTION, this.action);
            payload.Add(Constants.SE_LABEL, this.label);
            payload.Add(Constants.SE_PROPERTY, this.property);
            payload.Add(Constants.SE_VALUE, valueSet ? value.ToString() : null);
            return(AddDefaultPairs(payload));
        }
        // --- Helper Methods

        /// <summary>
        /// Adds the common key-value pairs to an event payload
        /// </summary>
        /// <param name="payload">The payload to append values to</param>
        /// <returns>The complete payload</returns>
        protected TrackerPayload AddDefaultPairs(TrackerPayload payload)
        {
            payload.Add(Constants.EID, eventId);
            payload.Add(Constants.TIMESTAMP, timestamp.ToString());
            return(payload);
        }