How to: track cart events(snippet)
We suggest sending two cart-related events to Omnisend: added product to cart
and started checkout
. Both events play a vital role in enabling the "Cart Abandonment" automation. For example, when a customer adds a product to their cart on your platform, you should send an added product to cart
event to Omnisend. Here's an example of how to accomplish this:
<script type="text/javascript">
omnisend.push(["track", "added product to cart", {
"origin": "api",
"eventVersion": "",
"properties":{
"abandonedCheckoutURL": "https://examople.com/cart/cartID/134035,",
"cartID": "134035",
"value": 19.99,
"currency": "EUR",
"addedItem": {
"productID": "373",
"productDescription": "Super duper product description",
"productImageURL": "https://example.com/inages/123.jpg",
"productPrice": 19.99,
"productTitle": "Super duper product",
"productURL": "https://example/com/abc"
},
"lineItems": [
{
"productID": "373",
"productDescription": "Super duper product description",
"productImageURL": "https://example.com/inages/123.jpg",
"productPrice": 19.99,
"productTitle": "Super duper product",
"productURL": "https://example/com/abc"
}
]
},
"contact": {
"id": "{contact id}",
"email": "{email}",
"phone": "{phone}",
"firstName": "Vanessa",
"lastName": "Kensington",
"birthdate": "1997-05-28",
"gender": "f",
"address": "9709 Highland Rd.",
"city": "New York",
"state": "NY",
"postalCode": "08723",
"country": "United States",
"customProperties": {
"favoriteColors": [
"red",
"blue"
],
"vipStatus": true,
"vipStatusDate": "2023-06-27T10:48:36Z",
"vipPoints": 100.59,
"friendlyTitle": "Miss Vanessa"
},
"tags": [
"vip",
"form:a12546asdwq"
],
"optIns": [
{
"channel": "email",
"createdAt": "2023-06-27T10:48:36Z",
"source": "form:omnisend-form:5d5cf027865hed74f4078q44:26"
}
],
"optOuts": [
{
"channel": "sms",
"createdAt": "2023-06-27T10:48:36Z",
"reason": "unsubscribed via email",
"source": "email link"
}
],
"consents": [
{
"channel": "email",
"createdAt": "2023-06-27T10:48:36Z",
"ip": "73.240.147.113",
"source": "form:omnisend-form:5d5cf027865hed74f4078q44:26",
"userAgent": "Mozilla/5.0"
}
]
}
}]);
</script>
- eventName. Either "added product to cart" or "started checkout"
- origin. Use
api
- eventVersion. Currently, use "" (empty)
- properties.
- contact. Optional. If the user has been identified by omnisend.identifyContact JavaScript function, this part can be skipped. contact object allows sending more details about the contact. NOTE: When using contact, ensure you provide at least one of the following values: id, email and/or phone. All other contact information is OPTIONAL.
For contact properties descriptions and validations check API contacts create reference.
It's important to note that you have the option to include custom properties in your events, which can then be utilised within the Omnisend platform for various marketing purposes and enhanced functionality.
To learn more:
Updated 2 months ago