Skip to content
Zid partners
Developer programsAn overview of every way to build on ZidApp PartnersPublish your app in the Zid App MarketTheme PartnersLaunch your theme in the Zid Theme Market
App MarketApps available to Zid merchantsTheme MarketThemes ready to install
Support
Partner help centreHow-to guides and troubleshootingDeveloper docsAPIs, SDKs and integration guidesBook a meetingA business or technical support call
What's new
BlogGuides and updates for developersChangelogThe latest partner platform updatesSuggest a featureThe feedback and ideas board
Partner enablement
Partner Ads SoonVisibility packages on Zid’s channelsCustom themesThemes built for one merchantPartner communityConnect with developers building on Zid
Zid library
Zid reportsEverything you need to know about the marketDeveloper guidesOfficial references to build on
العربيةLog inJoin as a partner

Partner programs

Developer programsApp PartnersTheme Partners

Browse the market

App MarketTheme Market

Support & enablement

Partner help centreDeveloper docsBook a meetingBlogChangelogSuggest a featurePartner Ads SoonCustom themesPartner communityZid reportsDeveloper guides

Language

العربية
Log inJoin as a partner
Home/Blog/APIs & integration
APIs & integration

Storefront events on Zid: track views, carts and purchases from your app scripts

Which storefront events Zid exposes, what each payload contains, how to add tracking scripts through Custom Snippets, and the zidTracking helpers for theme developers.

Nov 1, 20266 min read

What the event layer is for

App Scripts let your app insert JavaScript into merchant storefronts without the merchant editing any code. Zid lists uses such as conversion tracking, analytics, personalization and customizing storefront interactions. The docs describe the storefront events as officially exposed for client-side tracking and integration, whether your app is embedded in the merchant dashboard or external.

There are two kinds of script:

  • Global scripts load on every page.
  • Event-driven scripts run in response to a shopper's action, such as viewing a product, adding it to the cart or completing a purchase.
These are events in the shopper's browser inside the storefront. They're different from webhooks such as order.create, which Zid sends to your server. A good split is to rely on webhooks for authoritative order data and on storefront events for what happens in the browser.

Global objects: who is the shopper?

Three objects are available in the page's window scope:

  • window.customer: the logged-in customer, with id, name, firstname, lastname, mobile and email. It's empty when nobody is logged in.
  • window.customerAuthState: available immediately on page load, with isAuthenticated and isGuest.
  • window.customerAsync: a Promise that resolves with the customer data once it's fetched, useful when window.customer isn't ready yet.
(async function () {
  var auth = window.customerAuthState || {};
  if (!auth.isAuthenticated) return; // guest or logged out

  var customer = (window.customer && window.customer.id)
    ? window.customer
    : await window.customerAsync;

  // use customer.id to map the shopper to your own records
})();
The customer object includes email and mobile number. A good practice is to send only the identifiers your service needs, and to hash or drop personal data before it reaches any third-party tool.

The seven supported events

  1. Purchase: after a successful transaction.
  2. Product View: when a shopper views a product (productViewd).
  3. Add to Cart: when a product is added to the cart (productCart).
  4. Remove from Cart: when a product is removed from the cart (productCart).
  5. Start Checkout: when the shopper starts checkout.
  6. View Item List (new): when a list of products is viewed, such as a category page or search results.
  7. Select Item (new): when a shopper clicks a product in a list.

The unusual spellings productViewd and productCart are intentional. They match Zid's codebase, so use them exactly as written.

Product View, Add to Cart and Remove from Cart carry a single product object with id, name, sku, category, price and position (display order), and the two cart events add quantity. Select Item carries product (same structure as productViewd) and listName. View Item List carries listName and a products array with item_id, item_name, item_sku, currency, price, quantity and item_category.

Purchase and checkout payloads, current and legacy

The Purchase event carries order (the full order object), transaction_id (the order ID), value, currency and an items array. This example is built from the documented fields:

{
  "transaction_id": "order-123",
  "value": 199.98,
  "currency": "SAR",
  "items": [
    {
      "item_id": "product-1",
      "item_name": "Product Name",
      "item_sku": "SKU-123",
      "price": 99.99,
      "quantity": 2,
      "item_category": "Category Name"
    }
  ],
  "order": { }
}

Start Checkout now receives the full cart object: id, session_id, products (with product_id, name, sku, price and quantity), products_count, products_subtotal, totals, currency (the code is in cart_currency.code) and coupon.

Both events also have a documented legacy shape. Legacy Purchase sends a flat transactionItems array with the order number in id. Legacy Start Checkout sends flat fields such as cart_id, cart_total, currency and items, whose entries have item_id, item_name, item_price and item_quantity. If your script may meet both, normalize first:

function normalizePurchase(evt) {
  if (evt.items) {
    return { orderId: evt.transaction_id, value: evt.value,
             currency: evt.currency, items: evt.items };
  }
  var legacy = evt.transactionItems || [];
  return {
    orderId: evt.id,
    value: legacy.reduce(function (s, i) { return s + Number(i.total || 0); }, 0),
    currency: legacy.length ? legacy[0].currency : undefined,
    items: legacy.map(function (i) {
      return { item_id: i.id, item_name: i.name, item_sku: i.sku,
               price: i.price, quantity: i.quantity, item_category: i.category };
    })
  };
}

Delivering your script with Custom Snippets

  1. Open your app in the Partner Dashboard and go to General Settings.
  2. Click Add Snippet and enter your JavaScript or CSS.
  3. Choose the snippet's placement (such as header or footer) and configure any required parameters.
  4. Submit it for review and approval. You can modify or remove it at any time.

For mobile and hybrid setups, the documented Scripts manifest (GET /api/v1/scripts) shows how snippets are grouped: external_scripts holds approved remote script URLs, and app_scripts_bundle holds inline snippets under reserved keys: head, global_head_script, purchase_event, product_details_event, add_to_cart_event, remove_from_cart_event and start_checkout_event, plus params for identifiers such as pixel IDs.

Your script may run on a Vitrin theme or a legacy theme. Check window.vitrin, which is true only on Vitrin stores. If your remote script already uses query params, it receives vitrin=true on Vitrin stores, so you can serve a newer version without checking inside the script:

// Inside your script
var hasVitrin = window.vitrin == true;

// How Zid calls a remote script URL:
//   Vitrin: {script_url}?store={store_uuid}&vitrin=true
//   Legacy: {script_url}?store={store_uuid}
Zid asks you to test snippets on a development store before publishing, and to optimize them so they don't slow down storefront loading.

For theme developers: zidTracking

The JS Integration docs list two tracking events that theme developers call manually. Both are available on window.zidTracking:

  • zidTracking.sendGaSelectItemEvent({ product, listName, listId, index }) when a shopper clicks a product in a list, such as a related-products slider. Only product is required, listName defaults to "products", and index is 0-based. It's sent as select_item to GA4 and GTM.
  • zidTracking.sendGaCartDetailViewedEvent({ cart }) when you show cart contents outside the cart page, such as a mini-cart or drawer. It's sent as view_cart to GA4 and GTM, and as ViewCart to Facebook.
// Product card click in a list
zidTracking.sendGaSelectItemEvent({
  product: product,
  listName: 'Related Products',
  listId: 'related_products_pdp',
  index: 2
});

// Cart drawer opened (not on /cart)
const cart = await zid.cart.get();
window.zidTracking?.sendGaCartDetailViewedEvent({ cart });
view_cart fires automatically on the /cart page. Don't call it there, or it will be counted twice.

Key takeaways

  • Zid exposes seven storefront events: purchase, product view, add to cart, remove from cart, start checkout, view item list and select item.
  • Use window.customerAuthState for instant login state, and window.customerAsync when window.customer isn't ready.
  • Handle both the current and legacy payloads for purchase and start checkout.
  • Ship your scripts through Custom Snippets in the Partner Dashboard; they're reviewed before going live.
  • Theme developers call sendGaSelectItemEvent and sendGaCartDetailViewedEvent manually, and never call view_cart on /cart.

Sources

  1. StoreFront Events
  2. Understanding the Zid App Scripts and Event Layer
  3. Events (JS Integration)
  4. Cart (JS Integration)
  5. Scripts (Mobile Apps)
  6. Supporting both Vitrin and Legacy themes
  7. Create a public app
  8. Webhooks Overview

Start building on Zid

Sign up in the partner portal, then build and test on a development store.

Create your account →

Contents

  1. What the event layer is for
  2. Global objects: who is the shopper?
  3. The seven supported events
  4. Purchase and checkout payloads, current and legacy
  5. Delivering your script with Custom Snippets
  6. For theme developers: zidTracking

Share

Start building

Related articles

→
APIs & integration

Rate limits and errors on the Zid API: pace your requests, handle 429s and read error responses

How the 60-requests-per-minute limit works, how to back off on 429s, what error responses look like, and how pagination, caching and webhooks keep you under the limit.

6 min read
APIs & integration

The Zid ERP integration guide: what to build, in what order

A new 53-page partner guide: what an ERP, accounting or WMS integration needs from a Zid store — push vs pull, OAuth, money, returns and a go-live checklist.

5 min read
APIs & integration

Securing your Zid app: webhook auth, token protection, minimal scopes and TLS

Verify every webhook with Basic Auth, keep tokens and secrets on your server, request only the scopes you use, and pass Zid's TLS checks before review.

6 min read
Zid Partners

Partner programs

Developer programsApp PartnersTheme PartnersCreate your account

Resources

BlogZid reportsDeveloper docsPartner help centerChangelogRequest a feature

Enablement

Partner Ads Soon

Browse the market

App MarketTheme Market

Terms & policies

Partner terms and conditionsPrivacy policy

Get in touch

Book a business callBook a technical support callPartners community
Zid — Al-Qudrah Al-Taqniyah for Technology and Communicationالعربية
Al-Qudrah Al-Taqniyah for Technology and Communication CompanyCR No. 1010365366VAT No. 300827827900003