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 AntsomiRnSDK from '@antsomicorp/antsomirnsdk';
const items: Record<string, any>[] = [];
// Replace the object orderData, and userData with your object
orderData.lineItems.forEach((productDetail) => {
items.add({
type: "product",
id: productDetail.sku,
name: productDetail.name,
sale_price: +productDetail.salePrice,
quantity: +productDetail.quantity,
line_item_quantity: +productDetail.quantity,
line_item_unit_price: +productDetail.unitPrice,
line_item_discount_amount: +productDetail.discountAmount,
line_item_rounded_amount: +productDetail.salePrice,
});
});
const event: CDPEvent = {
en: "purchase_product",
items: items,
customerProps: {
customer_id: MD5Hash().generateMd5(userData.email ?? ''),
name: userData.name,
email: userData.email,
phone: userData.phoneNumber,
first_name: userData.firstName,
last_name: userData.lastName,
company: userData.company,
address_1: userData.address1,
address_2: userData.address2,
city: userData.city,
province: userData.province,
country: userData.country,
zip: userData.zip
},
objectProps: {
purchase: {
id: orderData.id,
name: orderData.id,
subtotal_amount: orderData.subtotal,
discount_amount: orderData?.discountAmount,
shipping_amount: orderData?.shippingAmount,
tax_amount: orderData?.tax,
total_amount: orderData?.total,
revenue: orderData.revenue,
promotion_code: orderData?.promotionCode,
customer_id: MD5Hash().generateMd5(userData.email ?? ''),
customer_name: userData.name,
customer_email: userData.email,
customer_phone: userData.phoneNumber,
billing_name: orderData.billing.name,
billing_address: orderData.billing.address,
billing_phone: orderData.billing.phoneNumber,
shipping_name: orderData.shipping.name,
shipping_address: orderData.shipping.address,
shipping_phone: orderData.shipping.phoneNumber,
shipping_method: orderData.shipping.shippingMethod,
payment_method: orderData.payment
}
},
eventProps: {
order_id: orderData.id,
revenue: orderData.revenue
}
};
await AntsomiRnSDK.track(event);
Last updated