定制 vskstudio/takt-symfony 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vskstudio/takt-symfony

Composer 安装命令:

composer require vskstudio/takt-symfony

包简介

Symfony bundle for Takt analytics: takt() Twig function + autowired Takt service for server-side events.

README 文档

README

Symfony bundle for Takt analytics. It wires the Takt snippet into your templates through a {{ takt() }} Twig function and exposes an autowired Takt service for server-side events.

Installation

composer require vskstudio/takt-symfony

If you use Symfony Flex, the bundle is enabled automatically. Otherwise add it manually to config/bundles.php:

return [
    // ...
    Vskstudio\Takt\Symfony\TaktBundle::class => ['all' => true],
];

Configuration

Create config/packages/takt.yaml:

takt:
  domain: 'example.com'
  endpoint: 'https://takt.example.com'
  api_key: '%env(TAKT_API_KEY)%'
  mode: 'inline'   # inline | cdn | asset
  outbound: false
  files: false
  exclude_localhost: true

The api_key must be ingest-scoped and domain-bound. Keep it out of source control via an environment variable.

Client-side tracking

Call the takt() Twig function inside the <head> of your base template:

<head>
    {# ... #}
    {{ takt() }}
</head>

Modes

  • inline — the tracking script is embedded directly in the page.
  • cdn — a <script> tag pointing at the Takt CDN is rendered.
  • asset — a <script> tag pointing at a self-hosted asset is rendered.

Server-side events

Autowire the Takt service in any controller or service:

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

final class CheckoutController
{
    public function __construct(private readonly Takt $takt)
    {
    }

    public function complete(): Response
    {
        $this->takt->event('Signup', ['plan' => 'pro'], new Revenue('29.00', 'EUR'));
        $this->takt->pageview();

        // ...
    }
}

The autowired service is bound to the current request: it automatically attributes events to the request's IP address and User-Agent.

Behind a proxy or load balancer? The attributed IP comes from Request::getClientIp(). It only honours X-Forwarded-For when the request is trusted, so configure framework.trusted_proxies for the real client IP. Without trusted proxies, clients can spoof the forwarded header — so never treat the attributed IP as authoritative.

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

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