mnapoli / piwik-twig-extension
此库将Matomo集成到Twig中
3.0.0
2020-04-24 14:45 UTC
Requires
- php: >=7.0
- twig/twig: ~2.10|~3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.13
- php-coveralls/php-coveralls: ^2.0
- symfony/phpunit-bridge: ^5.0
This package is auto-updated.
Last update: 2024-08-28 13:16:44 UTC
README
此库将 Matomo 集成到 Twig 中。 之前名为 PiwikTwigExtension。
安装
composer require "mnapoli/piwik-twig-extension"
使用
您有2种方式提供Matomo主机和站点ID
-
在创建扩展时(推荐)
$twig->addExtension(new MatomoTwigExtension('my-matomo-host.com', 123));
在模板中,您只需调用
{{ matomo() }}
。此方案适用于大多数情况。
-
在调用Twig函数时
$twig->addExtension(new MatomoTwigExtension());
在模板中,您必须提供主机和站点ID:
{{ matomo('my-matomo-host.com', 123) }}
。如果您想在模板中自定义站点ID或Matomo主机,此方案非常完美。
别忘了在HTML文档的末尾添加跟踪脚本,例如
<!DOCTYPE html> <html> <head> ... </head> <body> ... {{ matomo() }} </body> </html>
开发环境
在某些环境中,您可能想要禁用Matomo的跟踪(例如在您的本地机器上)。通过将 $enabled
参数传递为 false
可以轻松实现这一点
$twig->addExtension(new MatomoTwigExtension($host, $siteId, false));
许可证
此库遵循 MIT许可证 发布。