Docsllms.txtSign inGo to your sites

Updated

View as Markdown

Script reference

HTML
<script defer data-website-id="tb_YOUR_SITE_ID" data-domain="example.com" src="https://twelvebit.app/js/script.js"></script>

The script sends a page view on load and on each client-side navigation. It also sends goals, identify calls, clicks on outbound links, scroll exposure updates and one ping when the page is hidden (for time on site).

Attributes

AttributeDefaultWhat it does
data-website-idrequiredThe public id of the site (tb_…). Without it, the script logs a warning and stops.
data-domainnoneYour root domain, for example example.com. When the page host ends with this value, the cookies are set on .example.com, so www., app. and blog. share one visitor. Without it, cookies belong to the current host only.
data-api/api/e on the script's originThe URL that receives events. Use it when you proxy the script, for example data-api="/tb/e". Absolute and relative URLs work.
data-cookielessfalse"true" sets no cookies. The server makes a visitor id from a daily rotating hash. See Privacy.
data-consentnone"required" sets no cookies until your banner calls twelvebit("consent", true). Until then visits count in cookieless mode. See Privacy.
data-allow-localhostfalse"true" sends on localhost, 127.*, [::1], *.local and *.test. Local development is not tracked by default, by design: use it only when someone asks for a local test (see Local development).
data-hashfalse"true" counts hash changes (/#/pricing) as page views, for hash-routed apps. Without it, the hash is ignored.
data-disable-outboundfalse"true" stops the tracking of clicks on links to other hosts.
data-disable-scrollfalse"true" stops automatic scroll depth measurement.
data-allowed-hostnamesnoneComma list of your other root domains, for example "myshop.com,docs.io". Links to them carry the visitor, so one person stays one visitor across your domains. Add the domains in Settings → General → Other domains too.
data-disable-paymentsfalse"true" turns off payment detection from the success-page URL (see Revenue).
data-allow-iframefalse"true" tracks when the page runs inside an iframe.
data-debugfalse"true" logs to the console why the script does not track ([twelvebit] not tracking: localhost).

What the script stores

NameWhereLifetimeContent
_tb_vidFirst-party cookie1 yearRandom visitor id
_tb_sidFirst-party cookie30 minutes, renewed with each eventRandom session (visit) id
twelvebit_ignorelocalStorageUntil you remove it"true" excludes this browser

Cookies use SameSite=Lax and Secure on HTTPS. They are not HttpOnly, because your server reads them to attribute revenue. In cookieless mode the script sets no cookies.

When the script does not track

  • The host is localhost, 127.*, [::1], or ends with .local or .test (unless data-allow-localhost="true").
  • The page is a file: URL.
  • The browser is automated (navigator.webdriver, PhantomJS, Nightmare, Cypress, Selenium) or the user agent is a headless browser or an HTTP library.
  • The page runs inside an iframe (unless data-allow-iframe="true").
  • localStorage.twelvebit_ignore is "true".

In these cases window.twelvebit becomes a function that does nothing, so your calls never throw. On the server, twelvebit also drops requests from known bots and excluded IPs, paths, hostnames and countries.

Scroll depth

The Page panel shows the median maximum depth of measured page views. Select a page to see the share reaching 25%, 50%, 75% and 100%. In People, open a person and choose the journey's Table view to see depth beside each individual page view. Repeat views of the same URL stay separate.

Depth is the furthest viewport bottom divided by the largest document height observed for that page view. Content visible on arrival counts; a short page can reach 100% without a scroll. Lazy loading, expanding sections and infinite scroll can increase the denominator and revise an earlier percentage. This measures exposure, not whether someone read the content. Only the document scroll is measured; nested scrolling containers are not included.

Updates are sent for the initial measurement, newly reached quarter milestones and changed snapshots when navigating away or hiding the page. They update the original page view, never create goals or billable events, and do not extend visit time or change bounce/conversion counts. The existing tracking exclusions and page-view sampling apply. Use data-disable-scroll="true" to turn it off.

Missing updates, older trackers, imported history and unsupported clients have no measurement. They appear as unavailable and are excluded from the median and milestone percentages. The detail shows the measured and tracked page-view counts for the selected range and filters. Collection begins with the updated tracker; past scroll depth cannot be reconstructed.

JavaScript API

JavaScript
window.twelvebit("signup", { plan: "pro" });            // goal with props
window.twelvebit("identify", { user_id: "u_123", email: "ada@example.com", name: "Ada" });
window.twelvebit("payment", { email: "ada@example.com" }); // on the success page: links the payment to this visitor
window.twelvebit("pageview");                            // count the current URL now
window.twelvebit("consent", true);                       // your banner's choice (with data-consent="required")
  • Goal names are stored as lowercase snake_case, at most 64 characters ("Sign Up!" becomes sign_up). A name with no letters is dropped.
  • Props: up to 30 keys (64 characters each). Strings are cut to 255 characters. Objects are sent as JSON strings. null and undefined are dropped.
  • Use optional chaining (window.twelvebit?.(…)) when the script can be missing, for example in tests.

Queue calls before the script loads

The script loads with defer. Calls made before it runs are lost, unless you add this stub before the script tag. The script replays the queue when it loads.

HTML
<script>window.twelvebit = window.twelvebit || function () { (window.twelvebit.q = window.twelvebit.q || []).push(arguments); };</script>
<script defer data-website-id="tb_YOUR_SITE_ID" data-domain="example.com" src="https://twelvebit.app/js/script.js"></script>

HTML attributes

HTML
<button data-tb-goal="signup" data-tb-goal-plan="pro" data-tb-goal-billing-cycle="yearly">Start</button>

A click on an element with data-tb-goal (or on anything inside it), or Enter or Space when it has focus, sends that goal. Each data-tb-goal-<name> attribute becomes a prop; hyphens become underscores (billing_cycle). See Goals.

Scroll goals

HTML
<section data-tb-scroll="saw_pricing" data-tb-scroll-threshold="0.5" data-tb-scroll-delay="1000" data-tb-scroll-plan="pro">…</section>

The goal fires once per page when the element is visible: threshold is the visible share (0 to 1, default 0.5) and delay the time in milliseconds it must stay visible (default 0). Other data-tb-scroll-<name> attributes become props, and scroll_percentage is added. Elements added later, for example by a router, are picked up.

Payments from the success page

When a page URL has session_id=cs_… (Stripe Checkout and Payment Links) or checkout_id (Polar), the script sends a payment event with that id once per tab. When the payment arrives from the provider, twelvebit links it to this visit, even when the checkout had no metadata. Turn it off with data-disable-payments="true".

Cross-domain

With data-allowed-hostnames, links to those domains get _tb_vid and _tb_sid parameters. The script on the other domain keeps the same visitor and session only when the visitor came from one of the allowed domains (by the referrer), and it removes the parameters from the address bar. For Lemon Squeezy and Paddle, pass the visitor in the checkout data instead (see Revenue).

Page views and navigation

  • The first page view carries document.referrer. Later page views in the same page load do not.
  • The script wraps history.pushState and history.replaceState and listens to popstate, so client-side routers work without extra code.
  • A page view is sent only when the URL changes. The query string counts; the hash counts only with data-hash="true".
  • Prerendered pages count when they become visible.
  • UTM parameters (utm_source, utm_medium, utm_campaign, utm_term, utm_content) and ref, via or source in the URL set the source of the visit. utm_id (or campaign_id) is the campaign ID: it matches the visit to a connected Meta Ads or Google Ads campaign.

A click on an http or https link to another host sends an outbound event with the link URL. Links to a subdomain are other hosts too. The event uses sendBeacon, so it is not lost when the page unloads. Turn it off with data-disable-outbound="true".

Time on site

When the page is hidden (tab change, close), the script sends one small ping. It moves the end time of the visit, so time on site is correct for one-page visits.

Transport

Events go to data-api (default https://twelvebit.app/api/e) as a POST with a text/plain JSON body, so there is no CORS preflight. The request uses keepalive and sends no cookies to twelvebit. Bodies larger than 16 KB are rejected.