public void AddCustomEvent(Portable.Analytics.CustomEvent customEvent) { if (customEvent == null || string.IsNullOrEmpty(customEvent.EventName)) { return; } string eventName = customEvent.EventName; double eventValue = customEvent.EventValue; string transactionId = customEvent.TransactionId; string interactionType = customEvent.InteractionType; string interactionId = customEvent.InteractionId; UACustomEvent uaEvent = UACustomEvent.Event(eventName, eventValue); if (!string.IsNullOrEmpty(transactionId)) { uaEvent.TransactionID = transactionId; } if (!string.IsNullOrEmpty(interactionId)) { uaEvent.InteractionID = interactionId; } if (!string.IsNullOrEmpty(interactionType)) { uaEvent.InteractionType = interactionType; } if (customEvent.PropertyList != null) { foreach (dynamic property in customEvent.PropertyList) { if (string.IsNullOrEmpty(property.name)) { continue; } if (property.value is string) { uaEvent.SetStringProperty(property.stringValue, property.name); } else if (property.value is double) { uaEvent.SetNumberProperty(property.doubleValue, property.name); } else if (property.value is bool) { uaEvent.SetBoolProperty(property.boolValue, property.name); } else if (property.value is string[]) { uaEvent.SetStringArrayProperty(property.stringArrayValue, property.name); } } } UAirship.Shared.Analytics.AddEvent(uaEvent); }
public void AddCustomEvent(CustomEvent customEvent) { if (customEvent == null || string.IsNullOrEmpty(customEvent.EventName)) { return; } string eventName = customEvent.EventName; double eventValue = customEvent.EventValue; string transactionId = customEvent.TransactionId; string interactionType = customEvent.InteractionType; string interactionId = customEvent.InteractionId; UACustomEvent uaEvent = UACustomEvent.Event(eventName, eventValue); if (!string.IsNullOrEmpty(transactionId)) { uaEvent.TransactionID = transactionId; } if (!string.IsNullOrEmpty(interactionId)) { uaEvent.InteractionID = interactionId; } if (!string.IsNullOrEmpty(interactionType)) { uaEvent.InteractionType = interactionType; } if (customEvent.PropertyList != null) { NSMutableDictionary <NSString, NSObject> propertyDictionary = new NSMutableDictionary <NSString, NSObject>(); foreach (dynamic property in customEvent.PropertyList) { if (string.IsNullOrEmpty(property.name)) { continue; } NSString key = (NSString)property.name; NSObject value = NSObject.FromObject(property.value); if (property is CustomEvent.Property <string[]> stringArrayProperty) { value = NSArray.FromObjects(stringArrayProperty.value); propertyDictionary.SetValueForKey(value, key); } if (value != null) { propertyDictionary.SetValueForKey(value, key); } } if (propertyDictionary.Count > 0) { uaEvent.Properties = new NSDictionary <NSString, NSObject>(propertyDictionary.Keys, propertyDictionary.Values); } } UAirship.Analytics.AddEvent(uaEvent); }