Tracking Events

Must Read

We recommend that you get yourself acquainted with the concept of System Events, Custom Events, and their attributes before proceeding. Doing so will help you understand the workings of this section, better.

Antsomi offers two distinct methods to facilitate event tracking within your application. The first method, trackScreen(), should be triggered whenever your user interacts with any screen within your application. The second method, track(), serves as a comprehensive solution for tracking various events, encompassing both System Events and Custom Events, providing you with a unified approach to monitor user interactions and behaviors effectively.

Tracking Event Screen View

Screen View events can be effortlessly tracked using the AntsomiSDK's trackScreen() method in your Flutter application. This method allows you to monitor user interactions with various screens and gather valuable insights.

import AntsomiFramework

Antsomi.shared.trackScreen(name: name,title: title, type : type)

Tracking Other Events

Other events can be effortlessly tracked using the AntsomiSDK's track() method within your Flutter application. This method allows you to monitor user interactions and events beyond screen views, providing you with comprehensive insights into user behavior. Additionally, you have the flexibility to include associated data as Event Attributes with each event, enriching your Antsomi dashboard with valuable contextual information.

For example, the add-to-cart event can be tracked by below

import AntsomiFramework

var trackEvent = CDPEvent(en: "add_to_cart")
        
trackEvent.setItems(items: [[
    "type": "product",
    "id": "123",
    "name": "T-shirt",
    "quantity": 2,
    "price": 70000
]]);
        
trackEvent.setEventProperties(eventProperties: [
    "event_source": "add_to_cart",
    "cart_subtotal": 140000,
    "cart_item_count": 2
])

trackEvent.setObjectProperties(objectProperties: [
    "store": [
        "id": 876554,
        "name": "HCM shop"
    ]
])
        
trackEvent.setCustomerProperties(customerProperties: [
    "name": "Join",
    "customer_id": "23123"
])
        
Antsomi.shared.track(event: trackEvent)

Notice about the setter setObjectProperties() and setEventProperties()

  • The setObjectProperties() setter accepts a map as its parameter, where the key represents the internal code of the CDP Business Object, and the value is another map. This inner map contains key-value pairs, with the key being the internal code of the object attribute and the value representing the attribute value.

  • You can include multiple objects in the setter as needed, but it's important to note that only the object registered in the CDP365 event settings can have its value updated through the event. Any other objects will be excluded from our backend processing.

  • The setCustomerProperties() setter functions uniquely; when invoked, it automatically attaches customer data to the event data. This attachment persists until you call the resetCustomer() method.

  • Similarly, the setEventProperties() setter operates comparably. However, it accepts a parameter as a map, where the key corresponds to the Event Attribute's internal code, and the value denotes the attribute value. As with the setObjectProperties() setter, you can include multiple attributes as needed. Keep in mind that only the attributes registered in the system can be received in CDP.

Last updated