Script configuration reference
Every data- attribute the Datasense script reads, the window.datasense JavaScript API, and what the script ignores.
The script is one file under 4 KB, plain ES5, with no dependencies. Load it with defer so it never blocks rendering.
Builds
| Script | Visitor recognition |
|---|---|
/js/script.cookies.js |
First-party datasense_vid (400 days) and datasense_sid (30-minute session) cookies. The default for new sites. |
/js/script.js |
Nothing stored on the device. See cookieless tracking. |
Attributes
| Attribute | Default | What it does |
|---|---|---|
data-website-id |
required | Your site ID from the dashboard. |
data-api |
next to the script | Where events go. Defaults to /api/e beside the script, which is what makes the proxy work with no config. data-api-url works too. |
data-allowed-hostnames |
none | Comma-separated other domains of yours. Links to them carry the visitor along: see cross-domain tracking. |
data-disable-payments |
false |
Set to true to stop reading payment link success URLs (session_id, checkout_id, order_id, payment_id). See duplicate payments. |
data-allow-localhost |
false |
Set to true to record visits on localhost while you test. |
data-track-errors |
true |
Set to false to turn off error tracking. |
data-respect-dnt |
false |
Set to true to ignore browsers that send Do Not Track. |
data-replay |
false |
Set to true to load the session recorder. |
data-replay-api |
next to the script | Where replay chunks go, if not /api/replay beside the script. |
JavaScript API
| Call | What it does |
|---|---|
datasense("signup", { plan: "pro" }) |
Records a custom goal. |
datasense("identify", userId, traits) |
Ties the visitor to your user. See user identification. |
datasense("reset") |
Starts a new visitor and session (cookie script). Call it on sign-out. |
datasense("payment", { email }) |
Credits the payment with that customer email to this visit. See revenue attribution. |
datasense.sessionId() |
The current session ID, for revenue attribution. |
datasense.visitorId() |
The visitor ID (cookie script only; null on the cookieless one). |
Single-page apps
history.pushState, history.replaceState and the back button count as pageviews, once per URL. When the visitor moves on or hides the tab, the script reports the visible time they spent on the page, capped at 30 minutes.
What the script ignores
localhost,127.*,[::1],0.0.0.0andfile:pages, unlessdata-allow-localhost="true".- Automated browsers: WebDriver, Cypress, PhantomJS and Nightmare.
- Excluded visits.