tlb/umami-bundle
Composer 安装命令:
composer require tlb/umami-bundle
包简介
Symfony bundle for Umami v3 tracking, events, and API access.
关键字:
README 文档
README
TlbUmamiBundle integrates Umami analytics into Symfony applications.
It supports:
- Twig script rendering (
umami_script()) - Server-side event sending (
/api/send) - Reporting API calls for selected Umami v3 endpoints
- Both Umami Cloud API key auth and self-hosted username/password auth
Requirements
- PHP 8.1+
- Symfony 6.4+
- Umami v3
Intended package name: tlb/umami-bundle.
Installation
1) Install package
composer require tlb/umami-bundle
2) Register bundle
In config/bundles.php:
<?php return [ // ... Tlb\UmamiBundle\TlbUmamiBundle::class => ['all' => true], ];
Configuration
Create config/packages/umami.yaml:
umami: mode: self_hosted tracker: enabled: false script_url: '%env(string:UMAMI_TRACKER_SCRIPT_URL)%' website_id: '%env(string:UMAMI_TRACKER_WEBSITE_ID)%' host_url: '%env(string:UMAMI_TRACKER_HOST_URL)%' auto_track: '%env(bool:UMAMI_TRACKER_AUTO_TRACK)%' do_not_track: '%env(bool:UMAMI_TRACKER_DO_NOT_TRACK)%' domains: '%env(string:UMAMI_TRACKER_DOMAINS)%' tag: '%env(string:UMAMI_TRACKER_TAG)%' cache: '%env(bool:UMAMI_TRACKER_CACHE)%' api: enabled: false base_url: '' username: null password: null api_key: null cache_pool: null
Add env defaults:
UMAMI_TRACKER_SCRIPT_URL= UMAMI_TRACKER_WEBSITE_ID= UMAMI_BASE_URL= UMAMI_TRACKER_HOST_URL=${UMAMI_BASE_URL} UMAMI_TRACKER_AUTO_TRACK=true UMAMI_TRACKER_DO_NOT_TRACK=false UMAMI_TRACKER_DOMAINS= UMAMI_TRACKER_TAG= UMAMI_TRACKER_CACHE=false UMAMI_API_BASE_URL=${UMAMI_BASE_URL} UMAMI_API_USERNAME= UMAMI_API_PASSWORD= UMAMI_API_KEY= UMAMI_API_CACHE_POOL=cache.app
Then configure real values in .env.local or deployment environment variables.
UMAMI_TRACKER_DOMAINS supports both comma-separated values (example.com,www.example.com) and JSON array format (["example.com","www.example.com"]).
Switch feature flags in YAML:
- set
umami.mode: cloudfor cloud authentication - set
umami.tracker.enabled: trueto renderumami_script() - set
umami.api.enabled: trueto register API client/event sender services
Example values (prefer setting these in .env.local):
Self-hosted Umami
UMAMI_BASE_URL=https://analytics.example.com UMAMI_TRACKER_SCRIPT_URL=${UMAMI_BASE_URL}/script.js UMAMI_TRACKER_WEBSITE_ID=your-website-id UMAMI_API_USERNAME=admin UMAMI_API_PASSWORD=change-me
Umami Cloud
UMAMI_BASE_URL=https://api-gateway.umami.is UMAMI_TRACKER_SCRIPT_URL=https://cloud.umami.is/script.js UMAMI_TRACKER_WEBSITE_ID=your-website-id UMAMI_API_KEY=your-cloud-api-key
Usage
Twig tracking script
Render the configured script tag:
{{ umami_script() }}
Override selected attributes at render time:
{{ umami_script({
'data-tag': 'marketing',
'data-auto-track': 'false'
}) }}
API client
Inject Tlb\UmamiBundle\Client\UmamiApiClient:
<?php use Tlb\UmamiBundle\Client\UmamiApiClient; final class AnalyticsService { public function __construct(private readonly UmamiApiClient $umamiApiClient) { } public function summary(string $websiteId, int $startAt, int $endAt): array { return $this->umamiApiClient->getStats($websiteId, $startAt, $endAt); } }
Supported endpoints:
/api/websites/{id}/stats/api/websites/{id}/pageviews/api/websites/{id}/events/stats
Event sender
Inject Tlb\UmamiBundle\Event\UmamiEventSender:
$umamiEventSender->send( websiteId: 'website-id', url: 'https://example.com/pricing', hostname: 'example.com', eventName: 'cta_click', tag: 'marketing', data: ['plan' => 'pro'], );
Authentication behavior
cloudmode: sendsx-umami-api-keyheader.self_hostedmode: authenticates via/api/auth/login, stores bearer token, and can cache token in configured cache pool.- On
401/403from API requests, auth is invalidated and one re-auth/retry is attempted.
Development
Run tests:
php bin/phpunit
Symfony Flex recipe template
A ready-to-use recipe template is included at:
recipes/tlb/umami-bundle/1.0/manifest.jsonrecipes/tlb/umami-bundle/1.0/config/packages/umami.yamlrecipes/tlb/umami-bundle/1.0/.env
tlb/umami-bundle 适用场景与选型建议
tlb/umami-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「analytics」 「umami」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tlb/umami-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tlb/umami-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tlb/umami-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Analytics chooser extensions for site settings.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-15