# Introduction

The Storelink storefront JavaScript API lets you listen to shopper activity and
customize prices, fees, shipping rates, and checkout behavior on your store.


USE CASES

With the Storelink JavaScript API, you can perform the following:

 * Send storefront events to analytics and ad pixels such as Meta Pixel, TikTok
   Pixel, and Google Analytics 4.

 * Send placed order details to your own server or webhook endpoint.

 * Apply bulk or tiered product pricing based on quantity.

 * Add conditional checkout fees such as a Cash on Delivery (COD) charge or a
   weight-based handling fee.

 * Override shipping rates based on the delivery address or cart contents.

 * Block checkout when an order does not meet your store rules, such as a
   minimum order amount or an unsupported postal code.

 * Customize storefront layout and appearance using stable element selectors and
   CSS variables.


WHERE TO ADD CODE

In the Storelink dashboard, go to Settings > Integrations, open the Custom
script card, and click + Add script. Set Page to All Pages, then paste your code
inside <script> tags.

See How to add custom JavaScript to my online store
[https://store.link/help/article/1058-how-to-add-custom-javascript-to-my-online-store]
for step-by-step instructions.

Sample code structure for a custom script:

<script>
storelink.on('page:changed', function(page) {
  console.log('Current page:', page.pathname);
});
</script>


GLOBAL VARIABLE

The API is exposed through the global variable storelink (window.storelink). It
is defined before any custom script runs, so you can register handlers directly
at the top level of your script without waiting for the page to load.


STORELINK.ON(EVENT, HANDLER)

Registers a handler function for a storefront event. This is the only method on
storelink. Handlers can be synchronous or async functions, and they stay active
for the page session.

Sample code to register a handler when an item is added to the cart:

storelink.on('cart:item-added', function(item) {
  console.log('Added to cart:', item.id, item.qty);
});

Here, the parameter event is the event name string, and handler is a function
that receives the event payload.


TRACKING EVENTS AND FUNCTIONS

Storelink provides two kinds of events:

 * Tracking events fire when a shopper navigates, views a product, updates the
   cart, or places an order. Return values are ignored, and errors inside a
   handler are logged to the browser console without affecting the page.

 * Functions fire when a shopper selects a quantity, changes a payment method,
   or updates a shipping method or delivery address. They can return values that
   change what the shopper sees and what is sent with the order, including
   prices, fees, shipping rates, and checkout availability.


AVAILABLE EVENTS

The following events are supported by storelink.on(event, handler):

EventKindDescriptionpage:changed
[https://store.link/help/developer/article/1173]TrackingFires when the shopper
opens a page (first load and every navigation to a new path).product:viewed
[https://store.link/help/developer/article/1173]TrackingFires when a product
page opens and each time a different variant is selected.cart:item-added
[https://store.link/help/developer/article/1173]TrackingFires when a product is
added to the cart or its quantity is increased from a product
card.cart:item-removed
[https://store.link/help/developer/article/1173]TrackingFires when a product's
quantity is lowered from a product card, or it is removed from a card or the
cart.order:placed [https://store.link/help/developer/article/1173]TrackingFires
when an order is placed, before the shopper is sent to the summary page or
WhatsApp.product:quantity-selected
[https://store.link/help/developer/article/1174]FunctionFires when quantity or
variant changes on a product page or featured product, and for every cart row on
load and quantity change.checkout:payment-changed
[https://store.link/help/developer/article/1174]FunctionFires when the cart
opens, and again whenever the payment method, subtotal, coupon, or checkout step
changes.checkout:address-changed
[https://store.link/help/developer/article/1174]FunctionFires when the cart
opens, and again whenever the shipping method, delivery address, subtotal,
coupon, or checkout step changes.


LEGACY EVENT NAMES

Older scripts may use the legacy names below. They still work as aliases for the
current names, but new scripts should use the current names.

Legacy NameCurrent
Namepagechangepage:changedproductviewproduct:viewedaddtocartcart:item-addedremovefromcartcart:item-removedorderplacedorder:placed

What's Next: Continue to Events
[https://store.link/help/developer/article/1173].