Tracking script reference

Updated

Load script.js with data-site-id and data-domain; everything else is optional. Call window.datapocket(name, props) for goals: names and property keys are lowercase [a-z0-9_-], at most 10 properties, values cut to 255 characters. For a script that never changes, load a pinned version such as [email protected] with its published integrity hash.

Script files

FileUse it when
script.jsThe default. A first-party cookie (dp_vid) recognizes returning visitors for a year, which gives the most accurate attribution.
script.hash.jsYour app routes with the URL hash (/#/settings): hash changes count as pageviews and the hash is part of the path.
script.cookieless.jsYou can't set cookies. See cookieless mode for what you give up.
[email protected] (and script.hash@…, script.cookieless@…)You want a file that never changes, to pin with Subresource Integrity. See pinned versions.

All of them are served from https://datapocket.vo1d.studio/js/, or from your own domain through a first-party proxy.

Bot traffic

DataPocket drops automated traffic before it reaches your numbers and counts what it dropped, so the Bots card shows "Filtered bot traffic" with the reason for each hit:

ReasonWhat it catches
Crawlers and toolsKnown bot user agents, and headless or automated browsers (Puppeteer, Playwright, Selenium, navigator.webdriver).
Data centersVisitors whose network is a cloud or hosting provider (AWS, Google Cloud, Azure, Hetzner, OVH, DigitalOcean…). iCloud Private Relay, Cloudflare WARP and corporate security gateways such as Zscaler are never treated as data centers.
ScriptsRequests sent straight to DataPocket without the headers every browser adds (Sec-Fetch-* and Accept-Language).
BurstsOne address and browser starting many new visitors for your site within minutes, a bot that clears its cookies on every page.
PrerenderingPages the browser loaded in advance but never showed. From script 1.0.2 a prerendered page counts when it's shown.

If your visitors reach your site through a VPN that runs on a cloud provider, turn off the data-center filter under Settings → Tracking.

Crawlers that never run the script, such as GPTBot, ClaudeBot and PerplexityBot, are counted separately when your server reports them: see AI crawler tracking.

Attributes

AttributeWhat it does
data-site-idRequired. Your site's public id, from its Install page.
data-domainRequired. Your domain without www.. Cookies are set on it, so subdomains share one visitor.
data-allowed-hostnamesOther domains you own, comma-separated. Links to them carry the visitor along, so a journey across domains stays one visitor (not in cookieless mode).
data-excludePaths where nothing is sent, comma-separated. See excluding pages.
data-query-paramsQuery parameters to send besides the defaults, comma-separated (page,plan), or * for all of them. See what leaves the browser.
data-apiSend events to this URL instead of next to the script. Useful when your proxy serves the script and the event endpoint from different paths.
data-disable-vitals="true"Don't measure Core Web Vitals.
data-disable-payments="true"Don't read checkout return parameters (session_id, checkout_id, order_id) from the URL.
data-debug="true"Log every event to the console, and track inside iframes (skipped otherwise).
data-allow-localhost="true"Track on localhost and *.local (skipped otherwise).
data-allow-file-protocol="true"Track pages opened from file://.

To stop tracking your own visits in one browser, run localStorage.setItem("dp_ignore", "true") in its console.

JavaScript API

js
window.datapocket(name, properties)

window.datapocket("signup", { plan: "pro", source: "onboarding" })
  • name: the goal. It's lowercased, spaces become _, characters other than a-z 0-9 _ - : are removed and it's cut to 64 characters. payment and identify are reserved (below).
  • properties: optional. Keys are lowercased and must match [a-z0-9_-]{1,64}; at most 10; values are turned into strings and cut to 255 characters.
  • An invalid key or an 11th property drops the whole call, with a warning in the console and nothing sent.
  • window.datapocket.version is the script's version. window.datapocket.visitorId is set in cookieless mode once the first event has been answered.

Goals without JavaScript: data-dp-goal="signup" on any element counts a click, with data-dp-goal-<key>="value" attributes as properties; data-dp-scroll="pricing_seen" counts when the element scrolls into view (data-dp-scroll-threshold, 0 to 1, default 0.5; data-dp-scroll-delay in milliseconds).

Calling it before the script loads

The script loads with defer, so an inline script or your app's entry may run first. Define this queue before your first call; the script sends everything queued as soon as it runs:

html
<script>
  window.datapocket = window.datapocket || function () {
    (window.datapocket.q = window.datapocket.q || []).push(arguments);
  };
</script>

Identify and payment

  • datapocket("identify", { user_id: "u_123", name: "Ada", email: "[email protected]" }) links the visitor to your user, so payments your server reports by email or customer id find their visitor. user_id is required; name, email and image are optional. Not available in cookieless mode.
  • datapocket("payment", { transaction_id: "order_123" }) links this visitor to the payment your server reports to the Payment API with the same transaction_id, in either order, within a day. Only the id is sent: no email, no amount. Anyone could send a call for an id they guess, so it's used only when one visitor alone sent it; passing visitor_id from your server is more reliable. (Older versions took an email; it's now ignored with a console warning.)

What leaves the browser

Each event carries the page URL, the referrer, the screen size, the browser's language and time zone, and the visitor and session ids. Query strings often carry secrets (password-reset and magic-link tokens, signed URLs), so the script trims what it sends:

  • Page URL: only utm_*, ref, source, via and ad click ids (gclid, gbraid, wbraid, fbclid, msclkid, ttclid, twclid, li_fat_id) are kept from the query. Add others with data-query-params="page,plan", or send the whole query with data-query-params="*". The hash is sent only for hash routes (#/path), without its own query.
  • Referrer and outbound links: origin and path only.
  • The server applies its own filter too: parameters named like secrets (token, code, key, signature, password, redirect, pre-signed X-Amz-* and X-Goog-*…) are never stored, even with *.
  • Cookies set by script.js: dp_vid (visitor, 1 year), dp_vfs (first visit, 1 year), dp_vsn (visit count, 1 year), dp_sid (session, 30 minutes, renewed on activity). First-party, SameSite=Lax, readable by your own code so you can pass dp_vid to your checkout.

Excluding pages

data-exclude takes a comma-separated list, checked before every event, so single-page app navigation is covered:

PatternMatchesDoesn't match
/account/account only/account/billing, /accounts
/account/*/account/billing, /account/a/b/account, /accounts
/account*/account, /account/billing, /accounts/my/account

Your dashboard's excluded paths (Settings → Tracking) use the same syntax and are applied on the server, so they also cover events sent by older copies of your page.

Cookieless mode

script.cookieless.js sets no cookies. The server derives the visitor id from a hash of the IP address, the user agent and a salt that changes every day, and keeps the session id in the tab's sessionStorage. What that costs:

  • A returning visitor is a new visitor every day, so multi-day attribution (the visit that found a customer last week) is weaker.
  • Each tab is its own session.
  • No identify, and no carrying visitors across your domains.
  • There is no dp_vid cookie to pass to the Payment API. Use window.datapocket.visitorId instead (set once the first event has been answered), or link the payment from the browser with datapocket("payment", { transaction_id }).

Pinned versions

script.js is updated in place. Each release is also published as a file that never changes, /js/script@<version>.js, so you can pin it with Subresource Integrity. The browser then refuses to run the file if a single byte differs. Every release and its hash: https://datapocket.vo1d.studio/js/sri.json.

html
<script
  defer
  src="https://datapocket.vo1d.studio/js/[email protected]"
  integrity="sha384-MsNyCZ/DPx8RAIgpvlbt3Xu5P4nLTNb3fkJL3M1m11GcXaefXQiun6R/11wdkd+N"
  crossorigin="anonymous"
  data-site-id="YOUR_SITE_ID"
  data-domain="YOUR_DOMAIN"
></script>
Fileintegrity
[email protected]sha384-MsNyCZ/DPx8RAIgpvlbt3Xu5P4nLTNb3fkJL3M1m11GcXaefXQiun6R/11wdkd+N
[email protected]sha384-klopDNmlO9zk9bfLkbcNq5leZVlLH85RuKf0xxb5e7WvAp+ikX3OV/yX0PRJcWqr
[email protected]sha384-BCzLRGOeV+R7R7fespWD7sa9bfwS8W/5U2kwcXSwixWs1DGd444i9Img/ls4YXOQ

A pinned file doesn't get fixes; check sri.json for newer versions now and then. Behind a first-party proxy, use the same file name through your proxy (/dp/js/[email protected]): the hash stays the same.

Questions

Can I use the script with a Content Security Policy?
Yes. Allow the script's origin (or your own, when proxied) in script-src and the event endpoint in connect-src. With a pinned version you can also require its integrity hash.
Is there an npm package?
Not on the npm registry yet. Use the script tag, and the REST API from your server.

Related

Tracking script reference · DataPocket