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. Hybrid Apps
  2. Flutter

Tracking Events

Trigger user actions in your Flutter app with Antsomi SDK. Track events, understand user journeys & leverage insights for data-driven marketing.

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 'package:antsomisdk/antsomi.dart'; // Contains Antsomi SDK APIs

// Initialize AntsomiSDK object
antsomiSdk = Antsomi();

// Track event screen view, the value of the name could be any unique string 
// to differentiate each screen.
antsomiSdk.trackScreen(name: 'Product View', type: 'product_view');

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 'package:antsomisdk/antsomi.dart'; // Contains Antsomi SDK APIs
import 'package:antsomisdk/cdp_event.dart'; // Contains the CDPEvent class

final addToCartEvent = CDPEvent(en: 'add_to_cart_product');
List<Map<String, dynamic>> items = [];

// Build event data
// Replace the object cartModel with your object
cartModel.getProductsInCart().forEach((element) {
  final value = element as Map<String, dynamic>;
  final productDetail = value['product'] as Product;
  
  items.add({
    'type': 'product',
    'id': productDetail.sku ?? '',
    'name': productDetail.name ?? '',
    'sku': productDetail.sku,
    'price': double.tryParse(productDetail.salePrice ?? ''),
    'original_price': double.tryParse(productDetail.price ?? ''),
    'quantity': value['quantity'] as int
  });
});

// Include the Multiple Objects (items) in the event data
addToCartEvent.items = items;

// Include the Single-Object (dims) in the event data
addToCartEvent.objectProps = {
  'customers': {    
    'name': user.name ?? '',
    'customer_id': MD5Hash().generateMd5(user.email ?? ''),
  }
};

// Include more Event Attributes (extra) in the event data
addToCartEvent.eventProps = {
  'event_source': 'add_to_cart',
  'cart_subtotal': cartModel.getTotal() ?? 0.0,
  'cart_item_count': cartModel.totalCartQuantity
};

// Initialize AntsomiSDK object
antsomiSdk = Antsomi();

// Send the event data to CDP
antsomiSdk.track(event: addToCartEvent);

About the setter objectProps() and eventProps()

  • The objectProps() 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 customerProps() setter functions uniquely; when invoked, it automatically attaches customer data to the event data. This attachment persists until you call the removeCustomer() method.

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


For a sample event tracking template, you can refer to one of the links below:

PreviousTracking UsersNextSample E-Commerce Events

Last updated 1 year ago

E-Commerce Events