How to take actions based on store event?

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, 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

pagechange

Triggered when a page is changed

addtocart

Triggered when a product is added to the cart

removefromcart

Triggered when a product is removed from the cart

orderplaced

Triggered when an order is successfully placed

Usage

  1. Go to settings > Integrations.

  2. Click on the "connect" button for Custom script.

  3. 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>
  1. 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.


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 page object has the following properties:

id:string - The product's id

price: string - The selected item's price

qty: string - Qty added to cart

selectedVariant: object- Qty added to cart

selectedProduct: object- Qty added to cart


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 added to cart', product);
});

The page object has the following properties:

id:string - The product's id

price: string - The selected item's price

qty: string - Qty added to cart

selectedVariant: object- Qty added to cart

selectedProduct: object- Qty added to cart


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 page object has the following properties:

orderPlaced:'success' | 'failed' - Status of the current order

orderSheetAppend:'success' | 'failed' - Status for data appended to order sheet

orderNumber: number - The order number



Still need help?

Contact us

Power Features