public void TestInitException() { Unstructured ue = null; try { ue = new Unstructured().Build(); } catch (Exception e) { Assert.AreEqual("EventData cannot be null.", e.Message); } Assert.Null(ue); }
public void TestInitMinimal() { Unstructured ue = new Unstructured().SetEventData(new SelfDescribingJson("iglu:acme.com/demo/jsonschema/1-0-0", new Dictionary <string, object> { { "demo", "app" } })).Build(); Assert.NotNull(ue); Dictionary <string, object> payload = ue.GetPayload().GetDictionary(); Assert.AreEqual(4, payload.Count); Assert.AreEqual("ue", payload[Constants.EVENT]); CollectionAssert.AreEquivalent(JSON.Deserialize <Dictionary <string, object> >("{\"data\":{\"data\":{\"demo\":\"app\"}, \"schema\":\"iglu:acme.com/demo/jsonschema/1-0-0\"}, \"schema\":\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\"}"), JSON.Deserialize <Dictionary <string, object> >(payload[Constants.UNSTRUCTURED].ToString())); }
private void TrackEvent(iEventInterface snowPlowEvent) { SelfDescribingJson eventData = new SelfDescribingJson(GetSchemaForEvent(snowPlowEvent), snowPlowEvent.snowplowProperties()); Unstructured unstructured = new Unstructured(); unstructured.SetCustomContext(new List <IContext> { UserContext(), MobileContext() }); unstructured.SetEventData(eventData); unstructured.Build(); tracker.Track(unstructured); DebugLog($"[ANALYTICS] Track event: {snowPlowEvent.name()} -> {snowPlowEvent.debugDescription()}"); DebugLog($"[ANALYTICS] Payload: {unstructured.GetPayload().ToString()}"); Crashlytics.Log($"Snowplow event: {snowPlowEvent.debugDescription()}"); }
/// <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()); } }