Purchase Product(s)

When users successfully complete a purchase of one or more products, marking a conversion point in the user journey and indicating a successful transaction.

import 'package:antsomisdk/antsomi.dart'; // Contains Antsomi SDK APIs
import 'package:antsomisdk/cdp_event.dart'; // Contains the CDPEvent class

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

// Build event data
// Replace with your object
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
event.items = items;

// Include the Single Item Object(s) (dims) in the event data
event.objectProps = {
  'purchase': {    
    'id': newOrder?.id,
    'name': newOrder?.id,
    'customer_id': customerId,
    'customer_name': customerName,
    'customer_phone': cartModel.address?.phoneNumber ?? '',
    'revenue': cartModel.getTotal().toString(),
    'subtotal_price': cartModel.getSubTotal().toString(),
    'total_price': cartModel.getTotal().toString(),
    'total_quantity': cartModel.totalCartQuantity,
  }
};

// Set the Customer Objects to the event data
event.setCustomerProps = {
  'customers': {    
    'name': user.name ?? '',
    'customer_id': MD5Hash().generateMd5(user.email ?? ''),
  }
};

// Initialize AntsomiSDK object
antsomiSdk = Antsomi();

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

Last updated