Configuration
Takt is configured in two equivalent ways: via data-* attributes on the snippet tag (CDN), or via init() options (npm). Both drive the same settings.
data-* options (snippet)
| Attribute | Effect | Default |
|---|---|---|
data-domain | Site identifier in your dashboard | location.hostname |
data-script-origin | First-party origin to derive the endpoint from ({origin}/api/event) | https://taktlytics.com |
data-endpoint | Event ingestion endpoint — wins over data-script-origin | https://taktlytics.com/api/event |
data-exclude-localhost="false" | Also measures localhost / private IPs | excluded |
data-enabled="false" | Kill-switch — the tracker does nothing | enabled |
data-respect-dnt="false" | Opt out of the client-side Do Not Track guard (the GPC signal stays enforced at ingestion) | respected |
data-sample-rate="0.5" | Send only this fraction (0–1) of events | 1 (all) |
data-track-query | Keep the full query string and hash | stripped |
data-query-params="utm_source,utm_medium" | Keep only these query params | none |
Settings in detail
data-domain— always set it explicitly. Without it, Takt infers the domain fromlocation.hostname, which breaks aggregation if your site responds on several hosts (www, staging, test domain).data-script-origin/data-endpoint— by default, events are posted tohttps://taktlytics.com/api/event.data-script-originreplaces the origin the endpoint is derived from ({origin}/api/event) when you serve Takt from your own domain;data-endpointsets the full URL and wins overdata-script-origin. For a first-party proxy served on the same origin as your page, passdata-endpoint="/api/event"explicitly. See First-party proxy.- Automatic capture — outbound clicks, downloads, HTML-declared events and 404s are not part of the minimal snippet: they live in the
takt.auto.jsbundle and are enabled throughdata-auto(see below). data-exclude-localhost— enabled by default. Pass"false"to also measure localhost and private IPs.data-enabled="false"— total kill-switch: no listener is attached and nothing is ever sent.- Privacy & sampling — the snippet respects Do Not Track and Global Privacy Control (
Sec-GPCheader /navigator.globalPrivacyControl) and strips the query string by default. Tune these on the tag itself:data-respect-dnt="false"(opt out of the client-side DNT guard; the GPC signal stays enforced at ingestion),data-sample-rate="0.5"(send a fraction of events),data-track-query(keep the full query + hash),data-query-params="utm_source,utm_medium"(keep only an allowlist). Same semantics as the npm options below.
<script
defer
src="https://cdn.jsdelivr.net/npm/@vskstudio/takt-core/dist/takt.js"
data-domain="example.com"
data-query-params="utm_source,utm_medium"
></script> data-exclude-localhost flag protects your visitors' privacy, and the snippet always respects Do Not Track. Only disable these guardrails if you know exactly why.Automatic capture (data-auto)
The minimal takt.js snippet only measures pageviews. Automatic capture — outbound clicks, downloads, HTML-declared events and 404s — lives in the takt.auto.js bundle and is entirely opt-in through the data-auto attribute, which takes a comma-separated list.
| Attribute | Effect | Default |
|---|---|---|
data-auto="outbound" | Emits Outbound Link: Click on clicks to another domain | off |
data-auto="downloads" | Emits File Download on links pointing at a file | off |
data-auto="tagged" | Emits the events declared on [data-takt-event] elements | off |
data-auto="404" | Emits a 404 event on error pages | off |
data-downloads-ext="pdf,csv,epub" | Restricts which extensions count as a download | default list |
<script
defer
src="https://cdn.jsdelivr.net/npm/@vskstudio/takt-core/dist/takt.auto.js"
data-domain="example.com"
data-auto="outbound,downloads,tagged,404"
></script> data-auto, takt.auto.js behaves exactly like takt.js: a single pageview, nothing more. Every attribute from the previous table still applies to this bundle. Each capture is detailed in Automatic extensions.init() options (npm)
In the npm version, these same settings are passed as an object to init() (in camelCase for booleans):
import { init } from '@vskstudio/takt-core'
init({
domain: 'example.com', // required in practice
outbound: true, // tracks outbound links
files: true, // tracks downloads
excludeLocalhost: true, // default
respectDnt: true // default
}) init() creates a shared instance, fires an automatic pageview and wires up SPA navigation. Call it only once, at application startup.
With neither endpoint nor scriptOrigin, events are posted to https://taktlytics.com/api/event. Pass endpoint: '/api/event' if you proxy Takt on the same origin as your page, or scriptOrigin: 'https://example.com/_takt' to derive the endpoint from another origin.
Advanced options
These tune privacy, sampling and autocapture. enabled, sampleRate, trackQuery and queryParams also have a snippet data-* form (above), and tagged / notFound a data-auto form; debug, scrubUrl and exclude are npm-only (the ≤ 1 kB minimal snippet does not carry them).
| Option | Type | Default | Role |
|---|---|---|---|
enabled | boolean | true | Stops all sending when false (handy in staging) |
debug | boolean | false | Logs every event to the console (npm-only) |
sampleRate | number | 1 | Samples sent events (0–1) |
trackQuery | boolean | false | Keeps the query string as-is |
queryParams | string[] | — | Allowlist of query params to keep |
scrubUrl | (url) => url | — | Custom URL scrubbing (npm-only) |
exclude | string[] | — | Path prefixes never tracked, e.g. ['/app', '/account'] (segment-bounded, checked at send time; npm-only) |
tagged | boolean | false | Custom events from [data-takt-event] elements (snippet: data-auto="tagged") |
notFound | boolean | false | Reports a 404 event on error pages (snippet: data-auto="404") |
By default, the query string and hash are stripped from every URL before sending. trackQuery/queryParams/scrubUrl (npm) or data-track-query/data-query-params (snippet) tune it. See Privacy.
data-exclude-localhost → excludeLocalhost, data-script-origin → scriptOrigin, data-downloads-ext → fileExtensions. The semantics are identical between snippet and npm for the shared settings.