[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationTracker and custom events

Tracker and custom events

What the cookieless tracker records, and its JavaScript API for custom events and A/B variations.

The tracker is the script embedded on the visitor-facing site. Installation covers the embed. This page covers what the tracker records and the JavaScript API it gives page code.

What is recorded automatically

  • Pageviews. The tracker counts every page load and every SPA navigation. It hooks history.pushState, history.replaceState and popstate, because a client-side redirect also lands on a page. It also counts a page restored from the back-forward cache. A call that leaves the path unchanged, such as a query or hash update, is not a navigation. Hash routes such as #/pricing count as one page, because stored paths never carry the fragment.
  • Clicks and scroll depth. These feed the heatmaps, on a sample of page loads, 10 % by default. See Settings. Only clicks the visitor made count, so a script's element.click() does not. A click from the keyboard, with Enter or Space, is placed at the centre of the element it activated. Every sampled view reports the depth it reached when the visitor leaves, scrolled or not. The depth is 0 for a long page read above the fold, and 100 for a page shorter than the window.
  • Page snapshots. Only on websites that turned them on, and only on visits already sampled for clicks. A snapshot is a serialized rendering of the page that the heatmap is drawn over, with form values and marked elements masked. Page snapshots lists what is captured, what never is, and the markers.
  • Session context. The referrer, the screen size, the language, and all five utm_* parameters (source, medium, campaign, term and content) go onto the session. Query strings are dropped from stored paths. The backend derives the acquisition channel shown on the dashboards from the referrer, utm_medium and the ad click ids. See Acquisition. When the deployment configures a GeoIP database, the session also carries the visitor's country. The backend derives it from the request's IP address and never stores that address.

The tracker batches events, up to 25 per beacon, and sends them with sendBeacon to lose fewer events when a page unloads. Delivery is still best-effort. A blocked script or a failed network request can leave gaps. The backend identifies the visitor by an anonymous hash it computes itself. The tracker sets no cookie, uses no localStorage, and stores nothing on the device. Architecture has the details.

What the backend accepts

A beacon counts only when the browser-reported Origin, or the Referer when there is no Origin, matches the website's declared domains. The backend refuses a foreign host with a 403. It drops a request that carries neither header without an error, because no browser sends a beacon that way. It also drops declared bots and sources that send at machine rate.

The backend validates each event on its own. It drops and counts an invalid event, and keeps the rest of its batch. Architecture covers the guard chain. The guard keeps other sites' pages out of your data. It does not authenticate the sender, so a script that forges a browser's headers is accepted like any visitor.

Browser privacy signals

The tracker honours Do Not Track and Global Privacy Control by default. A browser that sends DNT or GPC (navigator.globalPrivacyControl) is not collected, unless the tag opts out with data-do-not-track="false".

A tag included twice

Including the tag twice, for example in the theme and in a tag manager, does no harm. The second copy logs a console warning and does nothing.

Excluded pages

A page that matches the tag's data-exclude-paths sends nothing. It sends no pageview, no click, no scroll depth and no snapshot, and no custom event while it is on screen. An SPA navigation away from the page counts the next page as usual.

A website id that can change

The tracker reads its tag's data-website-id as it goes:

  • When the attribute changes, the events already queued leave under the previous website, and the page on screen counts for the new one.
  • When the attribute is removed, nothing more is sent until it is set again.

That is how the dashboard's own tag follows sign-out and workspace switches. See Tracking the dashboard itself.

Removing or changing the attribute blocks new events at once, before the mutation observer runs. Events already queued still go out under the old website. The observer then activates the new website and counts the current page. The tracker discards events from the transition rather than count them for the wrong workspace. A tag that starts with no id stays paused, and it can activate later without loading the script again.

Custom events

Page code reports business events through the API the tracker installs:

js
window.dmsMarketing.track("signup_submitted", { plan: "pro" });
  • name. Required. Up to 50 characters. The tracker cuts a longer name.
  • data. An optional object, at most 4,096 characters once serialized to JSON. The backend drops an event with a larger payload and counts it, without a 400, and keeps the rest of the batch.

Custom events show in the KPI cards of the overview and in its Custom events card, with a count per name, such as which button gets clicked. They are also the second kind of funnel step. See Funnels. The funnel builder suggests the names the site already sends. The overview tags an event that ends a funnel as Goal.

Experiment variations

variation() answers the arm the backend assigned this visitor, and reports the exposure. See A/B tests.

js
window.dmsMarketing?.variation("hero-cta").then((arm) => {
  if (arm === "b") {
    showAlternateHero();
  }
});

The call returns a promise, so it runs as it is in a classic <script>. A top-level await works only in a module script. The builder's snippet has the same shape.

The call is asynchronous because the first call loads the visitor's assignments from the backend. Pages that never ask fetch nothing. A null answer means render the control. The answer is null when the key is unknown or not running, when collection is off, and under Do Not Track. The tracker reports the exposure only for the keys the page asked for, once per page load.

exposure(experiment, variation) is the low-level call for integrations that assign arms on their own. Prefer variation(). Either way, the backend records exposures only for a split that is running, so a stopped test stops counting whoever reports the arm.

Guard the call

The tracker installs window.dmsMarketing as a no-op when it collects nothing, under DNT or GPC, and while collection is paused. While collection is paused, the served script is cached for one minute and installs that no-op only. When the tag has no website id, the tracker installs its API and drops every call until an id is set.

window.dmsMarketing is absent when the script itself never runs. That happens when it is blocked, when it fails to load, or when the tag is a type="module" script, which has no document.currentScript. Guard the call in page code:

js
window.dmsMarketing?.track("signup_submitted");

Page snapshots

On a visit sampled for clicks, three seconds after load and in idle time, the tracker asks the backend whether it wants a capture of this page at this viewport width. It calls GET /api/marketing/snapshot.js?website=&path=&width=, plus &root=1 when the page scrolls an inner container (see Pages that scroll an inner container).

The answer is either empty or the capture script itself, which carries a one-time token. The capture script waits for the DOM to stop changing, serializes it, and posts the document with the token to POST /api/marketing/snapshot. When the capture is larger than the upload cap (snapshotMaxBytes, 1 MiB compressed by default), the script posts its size instead. That is what lets the console say the page is too heavy, rather than show nothing.

The tracker does not ask on websites that have not turned snapshots on, from inside a frame, on a hidden tab, or after three requests in one page load. SPA navigations ask again, within that limit. The tracker sends its queued pageview before it asks, because the backend accepts the upload only from the visitor the token was handed to, while that visit is on that page.

What is and is not captured gives the masking rules and the data-dms-marketing-mask and data-dms-marketing-block markers. Snapshot contract gives the guards on the endpoints.

Pages that scroll an inner container

An app shell often keeps its document as tall as the window and scrolls a container inside it, such as a dashboard's panel body or the main column of a sidebar layout. When the document itself does not scroll, the tracker takes the page's scroll root to be the first of these:

  1. The element marked data-marketing-scroll-root, if there is one.
  2. The largest visible element that scrolls vertically (overflow-y: auto or scroll, with content taller than its box) and covers more than half of the window. A scrolling list, code block or dropdown is not the page.
  3. The document.

The tracker then measures scroll depth on that element, and takes a click's document fraction (dy) in its content, as if the page were unrolled:

  • A click inside the element moves down by how far the element was scrolled.
  • A click below the element moves down by everything the element hides.
  • A click beside or above the element, in a sidebar or a header, does not move.

Captures mark the scroll root and record its whole content height, so the console's backdrop is unrolled too and the overlays line up with the content. Element anchors were already independent of scrolling.

Mark the container yourself when the guess could be wrong, for example with two containers side by side, or one that covers less than half of the window:

html
<main class="overflow-y-auto" data-marketing-scroll-root>…</main>

Settings reach the tracker within an hour

GET /api/marketing/tracker.js prepends the module's effective settings to the static file. The response carries a one-hour cache lifetime (TRACKER_CACHE_MAX_AGE_SECONDS). A sampling change on the Settings page therefore reaches returning visitors within that hour.