Example #1
0
        /// <summary>
        /// Figures out what kind of event is being tracked and
        /// then processes it accordingly.
        /// </summary>
        /// <param name="newEvent"></param>
        private void ProcessEvent(IEvent newEvent)
        {
            List <IContext> contexts = newEvent.GetContexts();
            string          eventId  = newEvent.GetEventId();
            Type            eType    = newEvent.GetType();

            if (eType == typeof(PageView) || eType == typeof(Structured))
            {
                CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(EcommerceTransaction))
            {
                CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId);
                EcommerceTransaction ecommerceTransaction = (EcommerceTransaction)newEvent;
                foreach (EcommerceTransactionItem item in ecommerceTransaction.GetItems())
                {
                    item.SetItemId(ecommerceTransaction.GetOrderId());
                    item.SetCurrency(ecommerceTransaction.GetCurrency());
                    item.SetDeviceCreatedTimestamp(ecommerceTransaction.GetDeviceCreatedTimestamp());
                    item.SetTrueTimestamp(ecommerceTransaction.GetTrueTimestamp());
                    CompleteAndTrackPayload((Payload)item.GetPayload(), item.GetContexts(), item.GetEventId());
                }
            }
            else if (eType == typeof(SelfDescribing))
            {
                SelfDescribing selfDescribing = (SelfDescribing)newEvent;
                selfDescribing.SetBase64Encode(_encodeBase64);
                CompleteAndTrackPayload((Payload)selfDescribing.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(ScreenView) || eType == typeof(Timing))
            {
                ProcessEvent(new SelfDescribing()
                             .SetEventData((SelfDescribingJson)newEvent.GetPayload())
                             .SetCustomContext(newEvent.GetContexts())
                             .SetDeviceCreatedTimestamp(newEvent.GetDeviceCreatedTimestamp())
                             .SetTrueTimestamp(newEvent.GetTrueTimestamp())
                             .SetEventId(newEvent.GetEventId())
                             .Build());
            }
        }
        /// <summary>
        /// Processes the event.
        /// </summary>
        /// <param name="newEvent">New event.</param>
        private void ProcessEvent(IEvent newEvent)
        {
            List <IContext> contexts = newEvent.GetContexts();
            string          eventId  = newEvent.GetEventId();
            Type            eType    = newEvent.GetType();

            if (eType == typeof(PageView) || eType == typeof(Structured))
            {
                AddTrackerPayload((TrackerPayload)newEvent.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(EcommerceTransaction))
            {
                AddTrackerPayload((TrackerPayload)newEvent.GetPayload(), contexts, eventId);
                EcommerceTransaction ecommerceTransaction = (EcommerceTransaction)newEvent;
                foreach (EcommerceTransactionItem item in ecommerceTransaction.GetItems())
                {
                    item.SetItemId(ecommerceTransaction.GetOrderId());
                    item.SetCurrency(ecommerceTransaction.GetCurrency());
                    item.SetTimestamp(ecommerceTransaction.GetTimestamp());
                    AddTrackerPayload((TrackerPayload)item.GetPayload(), item.GetContexts(), item.GetEventId());
                }
            }
            else if (eType == typeof(Unstructured))
            {
                Unstructured unstruct = (Unstructured)newEvent;
                unstruct.SetBase64Encode(this.base64Encoded);
                AddTrackerPayload((TrackerPayload)unstruct.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(Timing) || eType == typeof(ScreenView))
            {
                this.ProcessEvent(new Unstructured()
                                  .SetEventData((SelfDescribingJson)newEvent.GetPayload())
                                  .SetCustomContext(newEvent.GetContexts())
                                  .SetTimestamp(newEvent.GetTimestamp())
                                  .SetEventId(newEvent.GetEventId())
                                  .Build());
            }
        }