Skip to content

GTM tracking bridge

When checkout and side-cart events don’t reach Dialog automatically (anything that’s not Shopify or Prestashop), you wire them via the window.DialogTracking bridge. This is the most common path because almost everyone already has GTM tagging their cart and checkout events.

When the Dialog widget is loaded on a page, it exposes:

window.DialogTracking.track(eventName, payload)

You call this from GTM tags to forward an add_to_cart or purchase event to Dialog. Anything else is ignored — only those two events are accepted.

  • The Dialog widget script must be loaded on the page where you call window.DialogTracking.track(...). Most importantly, make sure the widget script tag fires on your purchase confirmation page — that’s the most common reason window.DialogTracking is undefined when your purchase tag fires.
  • You have edit access to your GTM container.
  • The events you want to forward already live in GTM (typically via existing dataLayer pushes from your site or a GA4 / Ecommerce setup).

Only these two:

  • add_to_cart
  • purchase
FieldTypeDescription
valuenumberTotal event value (cart subtotal for add_to_cart, order total for purchase).
currencystringISO currency code, e.g. "EUR", "USD".
itemsarray (optional)Items affected — see whitelist below.
FieldTypeDescription
transaction_idstringUnique transaction or order ID.

Whitelist (other fields are dropped):

  • item_id
  • item_name
  • price
  • quantity
  • item_brand
  • item_category
  • item_variant
  • index
  • coupon
  • discount

In GTM, create a Custom HTML tag named Dialog: forward purchase.

Trigger: your existing purchase trigger (typically on the order confirmation page).

<script>
if (window.DialogTracking && typeof window.DialogTracking.track === 'function') {
window.DialogTracking.track('purchase', {
transaction_id: 'TRANSACTION_ID',
value: VALUE,
currency: 'CURRENCY',
items: ITEMS
});
}
</script>

Replace TRANSACTION_ID, VALUE, CURRENCY, ITEMS with your GTM variables. items is optional.

<script>
if (window.DialogTracking && typeof window.DialogTracking.track === 'function') {
window.DialogTracking.track('add_to_cart', {
value: VALUE,
currency: 'CURRENCY',
items: ITEMS
});
}
</script>

The if (window.DialogTracking) guard is mandatory — see the race condition note below.

window.DialogTracking is set by the Dialog widget script after it has loaded and initialised. If your GTM tag fires before the widget script has run, window.DialogTracking is undefined and the call does nothing — the event is silently dropped.

The two safe patterns:

  1. Keep the if (window.DialogTracking) guard (always). At worst, an event is missed; at best, your tag never throws.
  2. Sequence your triggers. On a confirmation page, fire your purchase tag after the widget script has loaded — e.g. trigger on DOMContentLoaded or a custom event you push to the dataLayer once the widget says it’s ready.

Concretely: if your purchase tag fires on Page View - DOM Ready and the widget loads asynchronously, you’ll lose purchases. Switch to Window Loaded or wrap the call in a small retry loop:

<script>
(function tryTrack(attempts) {
if (window.DialogTracking && typeof window.DialogTracking.track === 'function') {
window.DialogTracking.track('purchase', {
transaction_id: 'TRANSACTION_ID',
value: VALUE,
currency: 'CURRENCY',
items: ITEMS
});
return;
}
if (attempts <= 0) return;
setTimeout(function () { tryTrack(attempts - 1); }, 200);
})(20); // up to 4 seconds of polling
</script>

This is the pattern we recommend on confirmation pages where you can’t afford to lose the purchase event.

For the bridge to exist, the Dialog widget script must run on the page where you call window.DialogTracking.track(...). The exact tag depends on your install:

  • GTM install → the same <script src="https://cdn.askdialog.com/assets/dialog-instant.js?..."></script> tag you set up in Install via Google Tag Manager. Make sure its trigger fires on your confirmation page as well, not just product pages.
  • SDK / React / Vue install → the SDK is bundled with your frontend, so the bridge is exposed wherever your storefront code runs. Just make sure your confirmation page is rendered by the same frontend (typical SPA) — server-rendered confirmation pages outside your SPA won’t have the SDK loaded.
  1. Open your site with the Dialog widget loaded.
  2. In the browser console, type window.DialogTracking. It must be defined.
  3. Trigger an add-to-cart. Confirm in the Dialog dashboard that the side-cart event fires.
  4. Trigger a purchase. Confirm the checkout event fires.
SymptomLikely causeFix
window.DialogTracking is undefinedWidget script not loaded on that page, or it hasn’t finished initialisingVerify the widget script tag is present and fires on this page; use the retry pattern above
Purchase tag fires on confirmation page but Dialog reports nothingRace condition — the tag fires before the widget script finishes loadingMove the trigger to Window Loaded, or wrap the call in the retry loop above
Wrong value or currencyGTM variables resolve too lateMove the tag to a later trigger or read from a stable dataLayer push
  • Tracking overview — what’s automatic vs manual per install path.
  • SDK custom tracking — the alternative when you’d rather call SDK methods directly from your frontend code.