private void TriggerOutcome(IOutcomeDefinition outcomeDefinition, TrackingEventData data, HttpContext context) { if (outcomeDefinition == null) { BadRequest("Please provide a valid outcome ID", context); return; } if (data.OutcomeCurrency == null) { BadRequest("Please provide a currency", context); return; } decimal value = 0.0m; decimal.TryParse(data.OutcomeValue, out value); if (data.OutcomeType == "interaction") { Tracker.Current.Interaction.RegisterOutcome(outcomeDefinition, data.OutcomeCurrency, value); return; } Tracker.Current.CurrentPage.RegisterOutcome(outcomeDefinition, data.OutcomeCurrency, value); }
private void Trigger(TrackingEventData data, HttpContext context) { if (data == null) { BadRequest("Please provide valid data.", context); return; } if (Guid.TryParse(data.Id, out var id)) { try { IEventDefinition evt; switch (data.Type) { case "outcome": TriggerOutcome(Tracker.MarketingDefinitions.Outcomes[id], data, context); return; default: evt = Tracker.MarketingDefinitions.PageEvents[id]; break; } if (evt == null) { BadRequest("Please provide a valid EventId", context); return; } PageEventData pageData = new PageEventData(evt.Alias, evt.Id) { Data = data?.Data, Text = data?.Text, }; if (Guid.TryParse(data.ItemId, out Guid itemId)) { pageData.ItemId = itemId; } Tracker.Current.CurrentPage.Register(pageData); } catch (Exception ex) { BadRequest($"An error occurred: {ex.Message}", context); return; } } else { BadRequest("Please provide a valid EventId", context); return; } }
// Use this for initialization void Start() { CustomData customData = new CustomData(); customData.Add("customKey1", "customValue1"); customData.Add("customKey2", "customValue2"); int[] coordinates = { 1, 2, 3 }; TrackingEventData data = new TrackingEventDataWithoutIDs( TrackingEvent.START, customData, "map1.level1.section1", coordinates ); //* JsonWriter writer = new JsonWriter(); writer.PrettyPrint = true; JsonMapper.ToJson(data, writer); string json = writer.ToString(); Debug.Log("obj=" + data); Debug.Log("serialized=" + json); TrackingEventData deserializedData = JsonMapper.ToObject <TrackingEventData>(json); /*/ * * // If you don't need a JsonWriter, use this. * string json = JsonMapper.ToJson(exampleClass); * * //*/ Debug.Log("deserialized:" + deserializedData); }