Tracker modules
The core script, the opt-in modules you turn on with one attribute, and every option.
The tracker is split in two. e.js is the core (1 KB gzipped): page views, engaged time, custom events and identify. Everything else is a separate module that the core loads from the same folder only when you ask for it with a data-* attribute, so pages that don't need a feature never download it.
<script defer data-site="SITE_ID" data-outbound data-vitals data-errors src="https://stancelens.com/e.js"></script>The core
- A page view on load, and on every single-page-app navigation (
pushState,replaceState, back and forward;#hashroutes withdata-hash). The URL is checked every 300 ms and before each custom event, so an event never arrives before its page's view. While a page is prerendering, nothing is sent. - Engaged time per page: visible time only, sent as one
$engagementbeacon when the page is hidden or left, if it was over half a second. stancelens("event", name, props)andstancelens.track(name, props). A numericprops.revenuewithprops.currencyrecords revenue.stancelens("identify", id, traits),stancelens("identify", null)andstancelens.reset(). See Identify users.stancelens.pageview()records the current URL; use it withdata-manual.stancelens.flag(key)loads the flags module on first use. See Feature flags.- Calls queued in
window.stancelens.qbefore the script ran are replayed (see the stub).
Every event is sent with navigator.sendBeacon, with the page URL, referrer, title, screen size and, after identify, the user ID. The core sets no cookies and only touches localStorage for stancelens_uid (after identify) and the stancelens_ignore flag you set yourself.
Core attributes
| Attribute | Default | |
|---|---|---|
data-site | required | Your site ID. |
data-api | api/event next to the script | Ingest URL, for proxying. When it ends in /event, the flags and replay modules use /flags and /replay beside it. |
data-hash | off | Keep the #fragment in page URLs and count hash changes as page views. |
data-manual | off | No automatic page views; call stancelens.pageview() yourself. Custom events then don't trigger a page view either. |
data-exclude | none | Comma-separated paths that send nothing; * matches anything: /admin/*,/preview. |
data-respect-dnt | off | Send nothing when Do Not Track or Global Privacy Control is on. |
data-allow-localhost | off | Also track on localhost, 127.*, IPv6 literals, 0.0.* and file:// pages, which are skipped by default. The server drops them too while Ignore localhost is on (details). |
A boolean attribute is on when present, unless its value is false, off or 0. Setting localStorage.stancelens_ignore to any value turns tracking off in that browser (details).
Modules
Add the attribute to the core's script tag. Each module is a file next to e.js (e-outbound.js, e-vitals.js, …) that loads after the core.
| Attribute | Sends | Details |
|---|---|---|
data-outbound | $outbound {url} | Clicks on links to another host. Links to downloads are reported by the downloads module instead. |
data-downloads | $download {url, ext} | Clicks on links to files. Extensions: data-download-ext="pdf,zip", default pdf,zip,dmg,exe,csv,xlsx,docx,mp4,gz. |
data-scroll | $scroll {depth} | The deepest point reached on a page (25, 50, 75 or 100), sent when the visitor leaves or hides the page, again only if they scrolled deeper. |
data-vitals | $web_vital {metric, value, rating} | LCP, INP, CLS, FCP and TTFB, measured with PerformanceObserver, sent once when the page is first hidden. See Web vitals. |
data-errors | $error {message, stack, source, line, col} | Uncaught errors and unhandled promise rejections, at most 10 per page load. |
data-tagged | your event name | Clicks on elements with data-el-event (submits for <form>). See HTML attributes. |
data-replay | recording chunks | Session replay (1.2 KB gzipped). A value between 0 and 1 records that share of page loads: data-replay="0.25". |
data-heatmap | $click, $scrollmap | Click positions and scroll depth for Heatmaps. No text or input values are read. |
Links with data-el-ignore (or inside an element that has it) are skipped by the outbound and downloads modules. The flags module has no attribute: the core loads it the first time you call stancelens.flag().
Everything in one file
e.full.js (2.7 KB gzipped) bundles the core with every module except replay and heatmaps, all switched on. Turn one off with its attribute set to off. data-replay still loads the replay module separately.
<script defer data-site="SITE_ID" data-scroll="off" src="https://stancelens.com/e.full.js"></script>Page views only
e0.js is 199 bytes gzipped. It sends a page view on load and on single-page-app navigation (pushState, replaceState and back/forward; fragment changes are ignored), with the URL and referrer, so UTM tags still come through. It defines no globals.
<script defer data-site="SITE_ID" src="https://stancelens.com/e0.js"></script>Compared with e.js it leaves out: custom events, identify, revenue, engaged time, page title, screen size (so iPads count as desktop), data-exclude, data-hash, data-manual, the in-browser localhost, Do Not Track, GPC and opt-out checks, the prerender check, and modules. Server-side exclusions in your site settings still apply. data-api points it at a proxied endpoint.
An inline beacon with no script file is 147 bytes including its tags. It sends one page view per full page load. Below about 100 bytes nothing useful fits: the site id, URL, referrer and endpoint alone take more.
Proxying the tracker? The modules load from the folder the core came from, so serve e-*.js next to your proxied e.js. See Proxying the script.