You can listen to five tracking events on your Storelink storefront to record shopper activity or send data to external tools.
Tracking events ignore any value returned by a handler. If a handler throws an error, Storelink logs it to the browser console without interrupting the shopper.
page:changed
Fires when the shopper opens a page, including the initial page load and every navigation to a new path.
Sample code to listen for page changes:
storelink.on('page:changed', function(page) {
console.log('Visited:', page.pathname, page.search);
});Here, the parameter page is an object containing the current path and query parameters.
| Field | Type | Description |
|---|---|---|
pathname | string | Current URL path (for example, '/product/denim-jacket'). |
search | object | Query string parameters as key-value string pairs. |
product:viewed
Fires when a product page opens, and again each time the shopper selects a different variant. Does not fire in the editor preview.
Sample code to track product views:
storelink.on('product:viewed', function(item) {
console.log('Viewed:', item.id, item.price, item.currency);
});Here, the parameter item is an object describing the viewed product and active variant. This event does not include a qty field.
| Field | Type | Description |
|---|---|---|
id | string | Product slug combined with variant values (for example, 'denim-jacket-L'). Matches the item id in order:placed. |
price | number | The variant's discounted price if set, otherwise its regular price. |
thumbnail | string | URL of the variant's first image, if available. |
currency | string | Store currency code (for example, 'USD'). |
selectedVariant | object | Active variant details, including key, value, price, discountedPrice, stock, availability, description, and images. |
selectedProduct | object | Full product object, including name, slug, category, and tags. |
cart:item-added
Fires when a product is added to the cart from the product page, or when its quantity is increased from a product card.
Sample code to track items added to the cart:
storelink.on('cart:item-added', function(item) {
console.log('Added:', item.selectedProduct.name, 'x', item.qty, item.currency);
});Here, the parameter item is the cart item object that was added.
| Field | Type | Description |
|---|---|---|
id | string | Product slug combined with variant values. |
qty | number | Quantity added to the cart. |
price | number | The variant's discounted price if set, otherwise its regular price. |
thumbnail | string | URL of the variant's first image, if available. |
currency | string | Store currency code. |
selectedVariant | object | Active variant details, including key, value, price, discountedPrice, stock, availability, description, and images. |
selectedProduct | object | Full product object, including name, slug, category, and tags. |
cart:item-removed
Fires when a product's quantity is lowered from a product card, or when it is removed from a product card or the cart.
Sample code to track items removed from the cart:
storelink.on('cart:item-removed', function(item) {
console.log('Removed or decreased:', item.id, 'Remaining qty:', item.qty);
});Here, the parameter item is the updated cart item object. Note that qty is the quantity left in the cart (0 when removed), and this event does not include a currency field.
| Field | Type | Description |
|---|---|---|
id | string | Product slug combined with variant values. |
qty | number | Quantity left in the cart (0 when removed completely). |
price | number | The variant's discounted price if set, otherwise its regular price. |
thumbnail | string | URL of the variant's first image, if available. |
selectedVariant | object | Active variant details, including key, value, price, discountedPrice, stock, availability, description, and images. |
selectedProduct | object | Full product object, including name, slug, category, and tags. |
order:placed
Fires when an order is placed, before the shopper is sent to the order summary page or WhatsApp.
Sample code to inspect a placed order:
storelink.on('order:placed', function(order) {
console.log('Order placed:', order.orderNumber, order.value, order.currency);
});Here, the parameter order contains the checkout response, order total, currency, and ordered items.
| Field | Type | Description |
|---|---|---|
orderPlaced | string | 'success' when the order succeeds. |
orderSheetAppend | string | Google Sheets sync status: 'success', 'failed', or 'skipped'. |
orderNumber | number | Order number assigned to the order. |
orderId | string | Unique order identifier. |
whatsappUrl | string | WhatsApp redirect URL, present on stores that take orders on WhatsApp. |
currency | string | Store currency code. |
value | number | Total order amount. |
items | array | List of ordered item objects (see table below). |
items Fields
Each entry in order.items contains the following fields:
| Field | Type | Description |
|---|---|---|
id | string | Item identifier matching the cart events. |
name | string | Product name. |
variant | string | Selected variant values as text (for example, 'Size - L, Color - Blue'). |
selectedVariantKey | string | Variant key string. |
selectedProduct | object | Summary product object with name, slug, category, and thumbnail. |
thumbnail | string | URL of the item image. |
qty | number | Quantity ordered. |
price | number | Unit price of the item. |
total | number | Line total for the item. |
originalPrice | number | Original price when a coupon or custom function changed the price (optional). |
discount | number | Discount amount applied to the item (optional). |
couponCode | string | Coupon code applied to the item (optional). |
Recipes
Meta Pixel
Sample code to send AddToCart and Purchase events to Meta Pixel (assuming the base Meta Pixel script is already loaded):
storelink.on('cart:item-added', function(item) {
if (typeof fbq !== 'function') return;
fbq('track', 'AddToCart', {
content_ids: [item.id],
content_name: item.selectedProduct.name,
content_type: 'product',
value: item.price * item.qty,
currency: item.currency
});
});
storelink.on('order:placed', function(order) {
if (typeof fbq !== 'function') return;
fbq('track', 'Purchase', {
content_ids: order.items.map(function(item) { return item.id; }),
content_type: 'product',
num_items: order.items.reduce(function(sum, item) { return sum + item.qty; }, 0),
value: order.value,
currency: order.currency
});
});TikTok Pixel
Sample code to send AddToCart and CompletePayment events to TikTok Pixel (assuming the base TikTok Pixel script is already loaded):
storelink.on('cart:item-added', function(item) {
if (typeof ttq === 'undefined') return;
ttq.track('AddToCart', {
contents: [{
content_id: item.id,
content_name: item.selectedProduct.name,
quantity: item.qty,
price: item.price
}],
value: item.price * item.qty,
currency: item.currency
});
});
storelink.on('order:placed', function(order) {
if (typeof ttq === 'undefined') return;
ttq.track('CompletePayment', {
contents: order.items.map(function(item) {
return {
content_id: item.id,
content_name: item.name,
quantity: item.qty,
price: item.price
};
}),
value: order.value,
currency: order.currency
});
});Google Analytics 4
Sample code to send add_to_cart and purchase events to Google Analytics 4 (assuming gtag is already loaded):
storelink.on('cart:item-added', function(item) {
if (typeof gtag !== 'function') return;
gtag('event', 'add_to_cart', {
currency: item.currency,
value: item.price * item.qty,
items: [{
item_id: item.id,
item_name: item.selectedProduct.name,
price: item.price,
quantity: item.qty
}]
});
});
storelink.on('order:placed', function(order) {
if (typeof gtag !== 'function') return;
gtag('event', 'purchase', {
transaction_id: String(order.orderNumber),
currency: order.currency,
value: order.value,
items: order.items.map(function(item) {
return {
item_id: item.id,
item_name: item.name,
item_variant: item.variant,
price: item.price,
quantity: item.qty
};
})
});
});Send Order Data to Your Own Endpoint
Sample code to forward placed orders to your own server with fetch:
storelink.on('order:placed', function(order) {
fetch('https://example.com/webhooks/storelink-order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
keepalive: true,
body: JSON.stringify({
orderId: order.orderId,
orderNumber: order.orderNumber,
currency: order.currency,
value: order.value,
items: order.items
})
});
});Here, keepalive: true lets the browser finish the request even as the storefront redirects the shopper to the summary page or WhatsApp.
What's Next: Continue to Functions.
