Unity User Events
User Events
A user event is an action that a user performs in your app. CleverTap records it with an event name and optional key-value properties for segmentation, targeting, and personalized messaging.
Note
For Unity SDK v2.4.2 or below, use the
CleverTapBinding
method instead ofCleverTap
method.
Record an Event
Record a basic user event without additional properties. This is ideal for tracking simple actions such as button clicks or page views.
// record basic event with no properties
CleverTap.RecordEvent("testEvent");
Record Event with Event Properties
Record an event with properties (key-value pairs) for additional context, such as user preferences or item details.
// Record Event with Event Properties
Dictionary<string, object> props = new Dictionary<string, object>(); // Variable name should be lowercase for consistency
props.Add("testKey", "testValue");
CleverTap.RecordEvent("testEventWithProps", props); // Use RecordEvent instead of RecordChargedEvent
Record Charged Event
Record a charged event to track transactions. Include payment details (for example, amount and currency) and a list of purchased items (for example, price, category, and quantity).
// Record Charged Event
Dictionary<string, object> chargeDetails = new Dictionary<string, object>();
chargeDetails.Add("amount", 500);
chargeDetails.Add("currency", "USD");
chargeDetails.Add("payment_mode", "Credit card");
Dictionary<string, object> item = new Dictionary<string, object>();
item.Add("price", 50);
item.Add("product_category", "books");
item.Add("quantity", 1);
Dictionary<string, object> item2 = new Dictionary<string, object>();
item2.Add("price", 100);
item2.Add("product_category", "plants");
item2.Add("quantity", 10);
List<Dictionary<string, object>> items = new List<Dictionary<string, object>>();
items.Add(item);
items.Add(item2);
CleverTap.RecordChargedEventWithDetailsAndItems(chargeDetails, items);
Updated 11 days ago