Technology and tracking

Tracking script

Also called track.js, tracking tag, tracking snippet.

Short answer

A tracking script is a piece of JavaScript the store places on its site to connect affiliate clicks with orders. The script picks up the click ID from the URL, stores it locally on the store's domain and sends it along when the customer completes a purchase.

Definition of Tracking script.

The script has 2 jobs. On arrival, it reads the click ID from the link's parameter and stores it in the browser's storage on the store's own domain – as a first-party cookie or in localStorage. At the purchase, it sends a conversion to the tracking server with order ID, order value and the stored click ID, so the server can link the sale to the right click.

The construction exists because the customer rarely buys in the same second as the click. Hours or days pass between visit and purchase, and the click ID has to survive in the meantime. Because storage happens on the store's own domain, it is not hit by browsers' blocking of third-party cookies – that is the whole point of moving the work into a script on the store's pages.

Installation is a snippet in the store's template plus a conversion call on the receipt page. On platforms such as Shopify and WooCommerce, an app or a plugin handles both. The script runs in the customer's browser and must therefore fail silently: a tracking error must never affect the buying experience itself.

What a good tracking script must be able to do

Four requirements are fixed: read the click ID from the URL on arrival, store it as first-party storage on the store's domain, send the conversion with order ID, order value excluding VAT and currency – and stay out of the way, so neither page speed nor checkout is affected.

The order ID is not optional: it is the key to deduplication, so the same order never counts twice, and to matching a later refund with the right commission. A conversion call without an order ID can be recorded, but never reconciled.

Tracking script vs. server-to-server (postback)

AspectTracking scriptServer-to-server
Where it runsin the customer's browserbetween the store's server and the tracking server
Vulnerabilityad blockers and closed tabs can stop the callunaffected by the browser
Installationa snippet in the templaterequires a developer or a platform integration
Data sourcewhat the browser knows at the moment of purchaseorder data directly from the store's system

The script is quickest to get going – server-to-server is the most robust. The combination, script for the click and server for the sale, gives the best of both.

How it goes wrong

  • 01

    The theme change that switched everything off

    A redesign or a template update removes the snippet, and tracking stops without an error message: the site works, sales continue, but no conversions are reported. Monitoring whether the script is still reporting is the only reliable alarm.

  • 02

    Order value including VAT

    If the gross amount is sent, commission is calculated on an amount that, in Denmark, is 25 % too high. The conversion call must send the order value excluding VAT – and without shipping, if the program calculates that way.

  • 03

    The script only loads on the home page

    If the snippet is not on every page, clicks that land directly on a product page via deep links are lost. The click ID must be captured where the customer actually arrives.

At Affilyflow

Tracking script in practice

Affilyflow's tracking script stores the click ID from the afid parameter as first-party storage on the store's own domain and sends the conversion to our server, where attribution is decided – the attribution window was already locked at the click. The same order ID can never be credited twice in the same program, and every tracking event is logged, including those that do not become sales.

Because a script can disappear in a theme change, we monitor ourselves whether the store's tracking has stopped reporting, and say so – instead of the error being discovered at the next settlement.

Frequently asked questions

How do I install a tracking script in my web shop?

The basic model is a script snippet in the page template and a conversion call on the order confirmation page with order ID and order value. On Shopify and WooCommerce, an app or a plugin usually handles the installation, so no code has to be touched by hand.

Can a tracking script break without me noticing?

Yes – it is the classic failure. A theme change or a template edit removes the snippet, and tracking stops silently while the store carries on. That is why tracking should be actively monitored; Affilyflow itself keeps an eye on whether a store's tracking is reporting, and says so.

Does a tracking script make my web shop slower?

Not measurably, if it is built properly. A tracking script is a few kilobytes, loads asynchronously and does not block the page's rendering. It must also fail silently, so an unavailable tracking server never affects the customer's purchase.

What is the difference between a tracking script and a tracking pixel?

A pixel is a single HTTP call from a specific page – it can report a sale but cannot remember anything. A tracking script runs logic: it reads the click ID from the URL, keeps it through the visit and sends it along when the purchase happens.