Tracking Events

Track user behavior events with Antsomi Android SDK for better user insights and improved app experiences

Must Read

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

Antsomi starts tracking some events as soon as you integrate the SDK. These are called System Events and track some generic user interactions with your app and campaigns. Here's a list of the System Events that we automatically track.

You can create Custom Events to track any other user interactions that are crucial for your business. Each Custom Event can further be defined by Event Attributes like price, quantity, category, and so on. Such granular data enables you to engage users through highly contextual and personalized campaigns.

Antsomi SDK offers two distinct methods to facilitate event tracking within your application. The first method, trackingScreen(), 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

By default, the Antsomi SDK will fire the event screen view automatically when the Activity stack is changed. However, you can turn this off and manually track it by utilizing the Antsomi SDK's trackingScreen() function. This method allows you to monitor user interactions with various screens and gather valuable insights.

import com.antsomi.AntsomiSdk;

public class MainActivity {
    // ... other fields and methods

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        String screenName = "home";
        String title = "MainActivity";
        String screenType = "activity_main";
        
        AntsomiSdk antsomiSdk = AntsomiSdk.getInstance();
        antsomiSdk.trackingScreen(screenName, title, screenType);
    }
}

Tracking Other Events

Other events can be effortlessly tracked using the AntsomiSDK's track() method within your Android 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 Custom Event Attributes with each event, enriching your Antsomi CDP365 dashboard with valuable contextual information.

For example, the Add to Cart Event can be tracked by below:

import com.antsomi.AntsomiSdk;
import com.antsomi.AntsomiTrackEvent;

public class ProductDetailActivity {
    // ... other fields and methods
    private CustomerModel customerModel;
    private ProductModel productModel;
    private CartModel cartModel;
    private StoreModel storeModel;
    
    private void handleAddToCart(int quantity) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
        String eventTime = sdf.format(date);

        AntsomiSdk antsomiSdk = AntsomiSdk.getInstance();

        Bundle product = new Bundle();
        product.putString("type", "product");
        product.putString("id", this.productModel.sku);
        product.putString("name", this.productModel.name);
        product.putString("sku", this.productModel.sku);
        product.putDouble("price", this.productModel.salePrice);        
        product.putDouble("original_price", this.productModel.price);
        product.putInt("quantity", quantity);

        ArrayList<Bundle> items = new ArrayList<>();
        items.add(article);
        
        Bundle customers = new Bundle();
        customers.putString("customer_id", this.customerModel.getCustomerId());
        customers.putString("name", this.customerModel.getCustomerName());
        
        Bundle stores = new Bundle();
        stores.putString("id", this.storeModel.getStoreId());
        stores.putString("name", this.storeModel.getStoreName());
        
        Bundle dims = new Bundle();
        dims.putBundle("store", stores);

        Bundle extra = new Bundle();
        extra.putString("event_source", "add_to_cart");
        extra.putDouble("cart_subtotal", this.cartModel.getTotal());
        extra.putInt("cart_item_count", this.cartModel.getTotalQuantity());
        extra.putString("identify_time", eventTime);

        AntsomiTrackEvent event = new AntsomiTrackEvent("add_to_cart_product");
        event.setItems(items);
        event.setCustomerProperties(customers);
        event.setObjectProperties(dims);
        event.setEventProperties(extra);
        
        antsomiSdk.track(event);
    }
}

Last updated