-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Akayashuu edited this page Jun 19, 2026
·
3 revisions
All snippet behavior is configured through the immutable Options value object.
use Vskstudio\Takt\Options;
use Vskstudio\Takt\Mode;
$options = new Options(
domain: 'example.com',
endpoint: '/api/event',
scriptOrigin: null,
outbound: false,
files: false,
fileExtensions: [],
tagged: false,
notFound: false,
excludeLocalhost: true,
nonce: null,
mode: Mode::Inline,
);| Name | Type | Default | Purpose |
|---|---|---|---|
domain |
string |
(required) | The registered site domain. Emitted as data-domain. |
endpoint |
string |
'/api/event' |
Path/URL the browser posts events to. Emitted as data-endpoint. |
scriptOrigin |
?string |
null |
First-party origin to serve the tracker + derive the endpoint from ({origin}/api/event) — dodge ad-blockers (endpoint wins over it). In Mode::Asset the loader src is also served from it ({origin}/takt/takt.auto.js). |
outbound |
bool |
false |
When true, tracks outbound link clicks (the outbound token in data-auto). |
files |
bool |
false |
When true, tracks file download clicks (the downloads token in data-auto). |
fileExtensions |
string[] |
[] |
Restrict download tracking to these extensions, e.g. ['pdf', 'zip'] — emitted as data-downloads-ext. Empty keeps the tracker's default list. |
tagged |
bool |
false |
When true, tracks elements marked in HTML with data-takt-event (the tagged token). |
notFound |
bool |
false |
When true, tracks 404 pageviews (the 404 token). |
excludeLocalhost |
bool |
true |
When false, emits data-exclude-localhost="false" so localhost traffic is also tracked. |
nonce |
?string |
null |
CSP nonce. When set, adds a nonce="…" attribute to the <script>. |
mode |
Mode |
Mode::Inline |
How the bundle is delivered (see below). |
All properties are readonly.
Autocapture is opt-in and bundled into the vendored takt.auto.js. Each toggle adds a token to a single data-auto attribute the tracker reads:
-
outbound: true— outbound link clicks (outbound) -
files: true— download clicks (downloads); narrow the matched extensions withfileExtensions: ['pdf', 'zip'], emitted asdata-downloads-ext -
tagged: true— elements tagged in HTML withdata-takt-event(tagged) -
notFound: true— 404 pageviews (404)
For config files or framework bindings, Options::fromArray() maps a loosely-typed array onto the constructor and accepts string mode names:
$options = Options::fromArray([
'domain' => 'example.com',
'mode' => 'cdn', // 'inline' | 'cdn' | 'asset'
'outbound' => true,
]);Unknown or missing keys fall back to the defaults above; an unrecognized mode falls back to Mode::Inline.
namespace Vskstudio\Takt;
enum Mode
{
case Inline;
case Cdn;
case Asset;
}| Case | What it emits |
|---|---|
Mode::Inline (default)
|
A <script> with the bundle embedded inline — no extra network request. |
Mode::Cdn |
A deferred <script defer src> loader pointing at the jsDelivr-hosted bundle (@vskstudio/takt-core). |
Mode::Asset |
A deferred <script defer src> loader pointing at a self-hosted /takt/takt.js. |
See The Snippet for rendered output of each mode.