Event
Any interaction a user has with your application can be defined as an event in your panel and application, allowing the Metrix library to provide you with related statistical data.
In the Metrix library, two types of events can be defined:
- Custom: Depending on your application’s logic and user interactions, you can create and send your custom events in the format described below.
- Revenue: A specific type of custom event related to revenue generated within your application, containing a measurable financial value.
Creating a Custom Event
To create a custom event, first register your desired event in the “Event Management” section of your panel and use its slug as the event name in the application.
The event occurrence can be recorded in the following way:
- Recording the event using the slug defined in the panel:
MetrixAnalytics.newEvent("my_event_slug");- Recording the event using a custom name: (In this case, an event with a unique slug will be automatically created in the panel)
MetrixAnalytics.newEventByName("my_event_name");Note: Events can be registered with any number of associated attributes:
For example, suppose you want to create a custom event in an online shopping application:
Map<String, Object> attributes = new HashMap<>();
attributes.put("product_name", "shirt");
attributes.put("purchase_date", "2024-11-20T11:24:03.000Z"); // use ISO 8601 to consider this attribute as s a date MetrixAnalytics.newEvent("purchase_event_slug", attributes);
// OR
MetrixAnalytics.newEventByName("purchase_event_name", attributes);The parameters for the newEvent method in this case are as follows:
- First parameter: The slug of your desired event as defined in the Metrix panel.
- Second parameter: A
Map<String, Object>that specifies the event’s attributes.
Note: Each event can have up to 50 attributes, with a maximum length of 512 bytes for each key and value.
Creating a Revenue Event
Using this function, you can create a revenue event. To do this, first register your desired event in the “Event Management” section of your panel and use its slug as the event name in the application.
Native
MetrixAnalytics.newRevenue("my_event_slug", 12000, RevenueCurrency.IRR);The parameters for the newRevenue method are as follows:
- First parameter: The slug of your desired event as defined in the Metrix panel.
- Second parameter: A numeric value representing the revenue amount.
- Third parameter: Specifies the currency used and can take one of three values: RevenueCurrency.IRR (default), RevenueCurrency.USD, or RevenueCurrency.EUR.
Alternatively, you can call the revenue event using a custom name (In this case, an event with a unique slug will be automatically created in the panel):
MetrixAnalytics.newRevenueByName("my_event_name", 12000, RevenueCurrency.IRR);