vskstudio/takt-core-php

Framework-agnostic PHP core for Takt analytics: browser snippet renderer + server-to-server event client.

Maintainers

Package info

github.com/vskstudio/takt-core-php

pkg:composer/vskstudio/takt-core-php

Statistics

Installs: 73

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.3 2026-06-12 22:46 UTC

This package is auto-updated.

Last update: 2026-06-12 22:47:21 UTC


README

Framework-agnostic PHP core for Takt analytics: a browser snippet renderer and a server-to-server event client.

Install

composer require vskstudio/takt-core-php

SnippetRenderer

Render the tracking snippet server-side and echo it into your <head>.

use Vskstudio\Takt\SnippetRenderer;
use Vskstudio\Takt\Options;

$renderer = new SnippetRenderer(new Options(
    domain: 'example.com',
    outbound: true,
    files: true,
));

echo $renderer->render();

Modes

The Mode enum controls how the bundle is delivered:

  • Mode::Inline (default) — embeds the bundle inline in a <script> tag that self-boots. No extra request, and CSP-friendly: pass nonce: in Options to emit a nonce attribute.
  • Mode::Cdn — emits a deferred loader pointing at the jsDelivr-hosted bundle.
  • Mode::Asset — emits a deferred loader pointing at a self-hosted /takt/takt.js.
use Vskstudio\Takt\Mode;

new Options(domain: 'example.com', mode: Mode::Cdn, nonce: $cspNonce);

The snippet honors domain, endpoint, outbound, files and excludeLocalhost. SPA tracking and Do-Not-Track respect are always on.

Takt (server-to-server client)

Send events directly from your backend, attributed to the real visitor.

use Vskstudio\Takt\Takt;
use Vskstudio\Takt\Revenue;

$takt = new Takt($endpoint, 'example.com', $apiKey);

$takt
    ->withVisitor($request->ip(), $request->userAgent())
    ->event('Signup', ['plan' => 'pro'], new Revenue('29.00', 'EUR'));

// or a pageview
$takt->withVisitor($ip, $userAgent)->pageview('https://example.com/welcome');
  • Requires an ingest-scoped API key bound to the domain.
  • Use ->withVisitor($ip, $userAgent) so events are attributed to the visitor rather than your server.
  • Fire-and-forget by default: transport errors are swallowed. Call ->strict() to get a client that throws on failure (handy in tests).
  • The PSR-18 HTTP client and PSR-17 factories are auto-discovered (php-http/discovery). You may also inject your own.

Wire payload

Events are posted as JSON with compact keys: n (name), d (domain), u (url), r (referrer), p (props) and $ (revenue). Screen width is not sent server-side.

License

MIT