You can listen for when certain events occur in your online store and take actions based on it. This feature can be used for Eg. to track the number of times a product is viewed, send events to a third-party analytics service or an ad pixel such as TikTok or Meta, and more.
To listen to a store event, you can use the storelink.on(event, callback) method where event is the name of the event and callback is the function to be called when the event is triggered.
Currently available events are:
Event | Description |
|---|---|
| Triggered when a page is changed |
| Triggered when a product page is viewed, and again when a different variant is selected |
| Triggered when a product is added to the cart |
| Triggered when a product is removed from the cart |
| Triggered when an order is successfully placed |
Usage
Go to settings > Integrations.
Click on the "connect" button for Custom script.
Register your callback functions for the events you want to track inside a
<script>tag. For example:
<script>
storelink.on('pagechange', (page) => {
console.log('Page changed to', page);
});
storelink.on('addtocart', (product) => {
console.log('Product added to cart', product);
});
</script>
Click on the "Save" button to save the integration.
Page change event
The pagechange event is triggered when a page is changed. The callback function will receive the new page as the first argument.
storelink.on('pagechange', (page) => {
console.log('Page changed to', page);
});
The page object has the following properties:
pathname: string - the URL path of the new page.
search: object - key-value Pair of Query Params in the URL.
Product view event
The productview event is triggered when a product page is viewed. It is triggered again each time the customer selects a different variant, such as another size or color. The callback function will receive the product as the first argument.
storelink.on('productview', (product) => {
console.log('Product viewed', product);
});
The product object has the following properties:
id: string - The product's id, including the selected variant (for example denim-jacket-L). The same id is used in the addtocart and orderplaced events.
price: number - The selected variant's price
currency: string - The store currency code, such as USD
thumbnail: string - URL of the selected variant's first image
selectedVariant: object - the selected variant, including its key, price, stock, availability, description and images
selectedProduct: object - the full product details, including its name and slug
Add to cart event
The addtocart event is triggered when a product is added to the cart. The callback function will receive the product as the first argument.
storelink.on('addtocart', (product) => {
console.log('Product added to cart', product);
});
The product object has the following properties:
id: string - The product's id, including the selected variant (for example denim-jacket-L)
price: number - The selected item's price
qty: number - quantity added to cart
currency: string - The store currency code, such as USD
thumbnail: string - URL of the selected variant's first image
selectedVariant: object - the variant chosen, such as size or color
selectedProduct: object - the full product details
Remove from cart event
The removefromcart event is triggered when a product is removed from the cart. The callback function will receive the product as the first argument.
storelink.on('removefromcart', (product) => {
console.log('Product removed from cart', product);
});
The product object has the following properties:
id:string - The product's id
price: string - The selected item's price
qty: string - quantity removed from cart
selectedVariant: object- the variant chosen, such as size or color
selectedProduct: object- the full product details
Order placed event
The orderplaced event is triggered when an order is successfully placed. The callback function will receive the order as the first argument.
storelink.on('orderplaced', (order) => {
console.log('Order placed', order);
});
The order object has the following properties:
orderPlaced: 'success' - Status of the current order
orderSheetAppend: 'success' | 'failed' | 'skipped' - Status for data appended to order sheet
orderNumber: number - The order number
orderId: string - The order's unique id
whatsappUrl: string - The WhatsApp link the customer is sent to, for stores that take orders on WhatsApp
currency: string - The store currency code, such as USD
value: number - The order total
items: array - The ordered items. Each item has id (the same id as in productview and addtocart), name, variant, price, qty and total.
Still need help?
Contact us