The eventCaller function is a utility function in JavaScript that allows you to trigger custom events with specific data. It takes an event name as a string and an optional data object as parameters. When called, the eventCaller function dispatches a custom event with the given name and the provided data, making it possible to capture custom events in your JavaScript applications.
Parameters
eventName (String): The name of the custom event to be dispatched. It should be a string representing the event's name.
data (Objectl): An data object to be passed along with the custom event. This data can be used by event listeners to access additional information related to the event.
Usage
Here's an example of how to use the eventCaller function for Product Click:
// Example: Triggering an event with data
const eventData = {
'actionField': {'list': 'Search Results'}, // Optional list property.
'products': [{
'name': productObj.name, // Name or ID is required.
'id': productObj.id,
'price': productObj.price,
'brand': productObj.brand,
'category': productObj.cat,
'variant': productObj.variant,
'position': productObj.position
}]
};
saleassist.track("productClick", eventData)
Here's an example of how to use the eventCaller function for Product Detail:
// Example: Triggering an event with data
const eventData = {
'actionField': {'list': 'Apparel Gallery'}, // 'detail' actions have an optional list property.
'products': [{
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray'
}]
};
saleassist.track("productDetail", eventData);
Here's an example of how to use the eventCaller function for Add To Cart:
// Example: Triggering an event with data
const eventData = {
'currencyCode': 'EUR',
'add': { // 'add' actionFieldObject measures.
'products': [{ // adding a product to a shopping cart.
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1
}]
}
};
saleassist.track("addToCart", eventData);
Here's an example of how to use the eventCaller function for Promotion Clicks:
// Example: Triggering an event with data
const eventData = {
'promotions': [ // Array of promoFieldObjects.
{
'id': 'JUNE_PROMO13', // ID or Name is required.
'name': 'June Sale',
'creative': 'banner1',
'position': 'slot1'
}]
};
saleassist.track("promotionClick", eventData);
Here's an example of how to use the eventCaller function for Checkout:
Here's an example of how to use the eventCaller function for Measuring Purchases:
// Example: Triggering an event with data
const eventData ={
'actionField': {
'id': 'T12345', // Transaction ID. Required for purchases and refunds.
'affiliation': 'Online Store',
'revenue': '35.43', // Total transaction value (incl. tax and shipping)
'tax':'4.90',
'shipping': '5.99',
'coupon': 'SUMMER_SALE'
},
'products': [{ // List of productFieldObjects.
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1,
'coupon': '' // Optional fields may be omitted or set to empty string.
},
{
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'quantity': 1
}]
};
saleassist.track("purchase", eventData);
Here's an example of how to use the eventCaller function for Measuring Refunds:
// Example: Triggering an event with data
const eventData ={
'actionField': {'id': 'T12345'} // Transaction ID. Required for purchases and refunds.
};
saleassist.track("refund", eventData);
Here's an example of how to use the eventCaller function for Partial Refunds:
// Example: Triggering an event with data
const eventData ={
'actionField': {'id': 'T12345'}, // Transaction ID.
'products': [
{'id': 'P4567', 'quantity': 1}, // Product ID and quantity. Required for partial refunds.
{'id': 'P8901','quantity': 2}
]
};
saleassist.track("refund", eventData);
Questions?
Please feel free to reach out via support@saleassist.ai if you need any help.