Skip to Content
TrackCrest Docs

JavaScript snippet

Track conversions from the browser when the advertiser can't send a server postback.

The server-to-server postback is the most reliable way to report conversions. When an advertiser can't call a URL from their server, for example on a hosted shop, this snippet does it from the browser instead.

Get it, with the advertiser's ID and token filled in, from Advertisers → Advertiser Integrations (pick the advertiser at the top) or the advertiser's Postback button (Web SDK tab).

1. Keep the click ID

Add this to every page of the advertiser's site, inside <head>. It saves the click_id from the landing page URL so it's still there at checkout:

<script>
(function () {
  var tid = new URLSearchParams(window.location.search).get('click_id')
         || sessionStorage.getItem('click_id');
  if (tid) sessionStorage.setItem('click_id', tid);
  window._trackConversion = function (goal, sale, orderId) {
    var img = new Image();
    img.src = 'https://yournetwork.trakcrt.com/p?m={ADVERTISER_ID}&token={POSTBACK_TOKEN}'
      + '&click_id=' + encodeURIComponent(sessionStorage.getItem('click_id') || '')
      + '&goal=' + encodeURIComponent(goal || 'default')
      + (sale != null ? '&sale=' + encodeURIComponent(sale) : '')
      + (orderId ? '&txn=' + encodeURIComponent(orderId) : '');
  };
})();
</script>

2. Report the conversion

On the thank-you page, call:

window._trackConversion('purchase', 49.99, 'ORDER-789');
ArgumentMeaning
goalThe event, e.g. purchase or lead. Empty means default.
saleThe order value. Needed for revenue-share offers.
orderIdThe advertiser's order ID, so a reload of the thank-you page isn't counted twice.

Things to know

  • The click ID is kept for the browser session only. A visitor who leaves and comes back days later in a new session can't be matched.
  • Ad blockers and strict privacy settings can stop browser calls. Prefer the server postback whenever possible.
  • The token in the snippet is visible to anyone who views the page source, so a server postback is also more secure.

On this page