vskstudio/takt-core-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vskstudio/takt-core-php

Composer 安装命令:

composer require vskstudio/takt-core-php

包简介

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

README 文档

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

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固