Tracking Events
Every interaction a user has with your application or game can be tracked as an event in Metrix. Accurate event tracking is crucial for understanding user behavior, measuring feature and campaign performance, and gaining valuable insights to grow your business.
Metrix provides the ability to define and send two main types of events via the Unity SDK:
- Action Events: User interactions with the application (e.g., button clicks, screen views).
- Revenue Events: Tracking financial transactions and earned revenue.
1. Sending Action Events
Action Events are used to record specific user interactions with your application’s or game’s UI.
Creating an Action Event
You can create and send Action Events using two primary methods:
-
Sending an Event using a Predefined Slug from the Dashboard: If your event is already defined in the Metrix dashboard and has a specific slug (a short, unique string like
aewqd), use theMetrix.NewEventmethod:Metrix.NewEvent("my_event_slug"); // Example: Metrix.NewEvent("product_viewed_slug"); -
Sending an Event using a Custom Name: If you prefer to use more descriptive and readable names for your events, or if you don’t want to pre-define them in the dashboard, use the
Metrix.NewEventByNamemethod. In this case, if an event with thiscustomNamedoesn’t already exist in the dashboard, it will be automatically created with your chosen name in Metrix.
-
Recommendation: For
customName, we recommend using theobject_verbpattern (e.g.,product_viewed,button_clicked) to align with Metrix’s Taxonomy.Metrix.NewEventByName("my_event_name"); // Example: Metrix.NewEventByName("product_viewed");
Adding Attributes to Action Events
You can send any number of attributes to provide more details along with your Action Events. Attributes should be in the form of a Dictionary<string, object> and support string, int, double, bool, or DateTime (in ISO 8601 format) data types.
var attributes = new Dictionary<string, object>();
attributes.Add("product_id", "P12345"); // String attribute
attributes.Add("category", "Electronics"); // String attribute
attributes.Add("price", 99.99); // Double attribute
attributes.Add("quantity", 1); // Integer attribute
attributes.Add("is_promo_item", true); // Boolean attribute
attributes.Add("view_date", "2024-11-20T11:24:03.000Z"); // Date attribute (ISO 8601 string)
attributes.Add("user_location", new Dictionary<string, object> { { "city", "Tehran" }, { "country", "Iran" } }); // Nested JSON Object
// Note: Direct JSON Array not shown, but can be managed by structuring your objects.
// Send event with Slug and Attributes
Metrix.NewEvent("purchase_event_slug", attributes);
// Send event with Custom Name and Attributes
Metrix.NewEventByName("purchase_event_name", attributes);Field Explanations for Methods:
- First Parameter (
slugorcustomName):slug: The unique identifier (string) for your event, as defined in the Metrix dashboard.customName: The desired name (string) for your event, which will be automatically created in the dashboard if it doesn’t exist.
- Second Parameter (
attributes): ADictionary<string, object>specifying the event’s properties.
2. Sending Revenue Events
Revenue Events are used to record financial transactions and revenue generated from your application. These events include a measurable financial value and currency.
- Important Note: Revenue Events do not support additional attributes.
Creating a Revenue Event
You can create and send Revenue Events using two methods (with a Slug or a Custom Name):
-
Sending an Event using a Predefined Slug from the Dashboard:
Metrix.NewRevenue("my_revenue_slug", 12000.0, 0); // Example: Metrix.NewRevenue("product_purchase", 12000.0, 0); -
Sending an Event using a Custom Name:
Metrix.NewRevenueByName("my_revenue_name", 12000.0, 0); // Example: Metrix.NewRevenueByName("in_app_purchase", 12000.0, 0);
Field Explanations for Methods:
- First Parameter (
slugorcustomName):slug: The unique identifier (string) for your revenue event.customName: The desired name (string) for your revenue event.
- Second Parameter (
revenueAmount): A numeric value (Double) representing the amount of revenue earned. - Third Parameter (
currencyCode): The currency code used. This value is determined as an integer:0for Iranian Rial (IRR)1for United States Dollar (USD)3for Euro (EUR)- Note: For information on other supported currency codes, please refer to the full API documentation or contact Metrix support.
3. Important Notes on Event Tracking
- Taxonomy:
- To ensure data quality and analyzability, adhere to Metrix’s Event Taxonomy and Tracking Plan. This includes using the
object_verbpattern forcustomNameand standardized naming forattributes.
- To ensure data quality and analyzability, adhere to Metrix’s Event Taxonomy and Tracking Plan. This includes using the
- Unique Per Device Events:
- Some events may need to be recorded only once per device (Unique Per Device). This feature must be enabled beforehand in the Metrix dashboard for the corresponding event slug. Currently, events automatically created via
customNamedo not have this feature and are not editable to include it. Therefore, for Unique Per Device events, always use theMetrix.NewEventmethod with the predefinedslugfrom the dashboard.
- Some events may need to be recorded only once per device (Unique Per Device). This feature must be enabled beforehand in the Metrix dashboard for the corresponding event slug. Currently, events automatically created via
- Attribute Limitations:
- Each event can have a maximum of 50
attributes(including standard and custom attributes), with a maximumkeyandvaluelength of 512 bytes for each attribute.
- Each event can have a maximum of 50