Developer Guide
API GuideDeveloper Guide
  • Overview
    • Getting Started
    • Customers and Visitors
    • Events and Business Objects (BOs)
      • Sample Event Templates
  • Website
    • Getting Started
      • Direct JS Implementation
      • JS Integration via GTM
      • Tracking Haravan website events
    • Tracking Users
    • Tracking Events
      • [Direct] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
      • [GTM] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
    • Web Push
  • Android
    • Getting Started
    • Tracking Users
    • Tracking Events
    • Push Messaging
    • App Inbox Messaging
  • iOS
    • Getting Started
      • Integration of Antsomi iOS SDK
    • Tracking Users
    • Tracking Events
    • Push Messaging
  • Hybrid Apps
    • React Native
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Apply Promotion Code
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
    • Flutter
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
      • App In-line Content
  • Antsomi Service Integrations
    • Media Template
    • Media JSON
      • Sample E-Commerce Events
        • Search for Product(s)
        • View Product
        • Add a Product to the Shopping Cart
        • Checkout Shopping Cart
        • Purchase Product(s)
      • Sample User Events
        • Sign-in
        • Sign-up
      • Sample Opt-in Events
        • Subscribe to Email marketing
        • Subscribe to OneSignal channel
  • 3rd Party Integrations
    • Shopify
      • Tracking Shopify website events
    • LINE
      • Integrating LINE Login with your web app
    • Google Ad Manager
      • Targeting CDP365 segment via PPID(s)
Powered by GitBook
On this page
  • Tracking Event Screen View
  • Tracking Other Events
  1. Android

Tracking Events

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

PreviousTracking UsersNextPush Messaging

Last updated 11 months ago

Must Read

We recommend that you get acquainted with , , 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 . These are called System Events and track some generic user interactions with your app and campaigns. 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);
    }
}
System Events
Custom Events
integrate the SDK
Here's a list of the System Events