Track an event
Use thetrack() method and pass the event name as the first parameter.Pass an object as the second parameter to send additional information with the event.
TwinalyzeAnalytics.track("productViewed",
{ //Add event propteries according to your needs
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
price: 3499,
currency: "INR",
})
window.TwinalyzeAnalytics.track("signUp",
{ //Add event propteries according to your needs
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
price: 3499,
currency: "INR",
})
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
eventName | String | Yes | Name of the custom event. |
properties | Object | No | Additional information related to the event. |
Examples
Track product viewed
TwinalyzeAnalytics.track("productViewed", {
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
price: 3499,
currency: "INR",
});
window.TwinalyzeAnalytics.track("productViewed", {
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
price: 3499,
currency: "INR",
});
Track add to cart
TwinalyzeAnalytics.track("productAddedToCart", {
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
quantity: 1,
price: 3499,
totalAmount: 3499,
currency: "INR",
});
window.TwinalyzeAnalytics.track("productAddedToCart", {
productId: "PROD_101",
productName: "Nike Air Running Shoes",
productCategory: "Footwear",
brand: "Nike",
variant: "Black / UK 9",
quantity: 1,
price: 3499,
totalAmount: 3499,
currency: "INR",
});
Track a purchase
TwinalyzeAnalytics.track("checkoutStarted", {
cartId: "CART_501",
itemCount: 2,
subtotal: 4498,
discountAmount: 500,
shippingAmount: 99,
totalAmount: 4097,
currency: "INR",
couponCode: "WELCOME500",
items: [
{
productId: "PROD_101",
productName: "Nike Air Running Shoes",
variant: "Black / UK 9",
quantity: 1,
price: 3499,
},
{
productId: "PROD_102",
productName: "Sports Ankle Socks",
variant: "White",
quantity: 1,
price: 999,
},
],
});
window.TwinalyzeAnalytics.track("checkoutStarted", {
cartId: "CART_501",
itemCount: 2,
subtotal: 4498,
discountAmount: 500,
shippingAmount: 99,
totalAmount: 4097,
currency: "INR",
couponCode: "WELCOME500",
items: [
{
productId: "PROD_101",
productName: "Nike Air Running Shoes",
variant: "Black / UK 9",
quantity: 1,
price: 3499,
},
{
productId: "PROD_102",
productName: "Sports Ankle Socks",
variant: "White",
quantity: 1,
price: 999,
},
],
});
Recommended naming
Use clear and consistent event names that describe the completed user action.TwinalyzeAnalytics.track("checkoutStarted");
TwinalyzeAnalytics.track("reportExported");
TwinalyzeAnalytics.track("checkoutCompleted");
TwinalyzeAnalytics.track("paymentFailed");
TwinalyzeAnalytics.track("subscriptionPurchased");
TwinalyzeAnalytics.track("subscriptionCancelled");
window.TwinalyzeAnalytics.track("checkoutStarted");
window.TwinalyzeAnalytics.track("reportExported");
window.TwinalyzeAnalytics.track("checkoutCompleted");
window.TwinalyzeAnalytics.track("paymentFailed");
window.TwinalyzeAnalytics.track("subscriptionPurchased");
window.TwinalyzeAnalytics.track("subscriptionCancelled");