Symfony/Laravel Compatibility: The package is a Symfony Bundle, not a Laravel package. While Laravel and Symfony share some PHP/Composer dependencies, this bundle is not natively compatible with Laravel’s architecture (e.g., no AppKernel.php, reliance on Symfony’s dependency injection container, and Twig integration). A Laravel TPM would need to either:
spatie/laravel-analytics).symfony/ux-live-component or a custom wrapper) or rewrite core functionality (e.g., Twig functions as Blade directives).Core Functionality Alignment:
@matomo).Low Feasibility for Laravel:
ContainerInterface, Twig, and Bundle system. Laravel’s ServiceProvider/Facade pattern cannot directly consume this.config.yml; Laravel prefers config/matomo.php or environment variables.{{ piwik_code() }} → @matomo).Workarounds:
resources/views/layouts/app.blade.php via a Blade directive.config('matomo.enabled') to toggle tracking.@if(config('matomo.enabled'))
<script>var _paq = window._paq = window._paq || []; ... </script>
@endif
HttpKernel in Laravel (overkill for tracking).MatomoServiceProvider to replicate the bundle’s logic.Illuminate\Foundation\Application) will reject these dependencies.spatie/laravel-analytics (if supporting multiple analytics tools).APP_ENV=local? Middleware or config-based?Laravel Incompatibility:
ContainerBuilder vs. Laravel’s Illuminate\Container.Compatible Alternatives:
| Feature | webfactory/piwik-bundle |
Manual Laravel | spatie/laravel-analytics |
|---|---|---|---|
| Matomo Tracking | ✅ (Twig) | ✅ (Blade) | ✅ (Supports Matomo) |
| Dev/Prod Toggle | ✅ (Config) | ✅ (Config) | ✅ (Config) |
| Async Loading | ❌ | ✅ | ✅ |
| Multi-Tool Support | ❌ | ❌ | ✅ (Google, Mixpanel) |
Assessment Phase (1 day):
Implementation Path A: Manual Laravel (Recommended):
config/matomo.php):
return [
'enabled' => env('MATOMO_ENABLED', false),
'site_id' => env('MATOMO_SITE_ID'),
'url' => env('MATOMO_URL'),
];
app/Providers/AppServiceProvider.php):
Blade::directive('matomo', function () {
if (config('matomo.enabled')) {
return <<<EOD
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//".concat(window.location.hostname).concat(config('matomo.url'));
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', config('matomo.site_id')]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
EOD;
}
});
@matomo
local env (optional):
public function handle($request, Closure $next) {
config(['matomo.enabled' => app()->environment('local') ? false : true]);
return $next($request);
}
Implementation Path B: Symfony Bridge (Not Recommended):
HttpKernel and Twig as Laravel dependencies (bloat).MatomoBundle that wraps the original bundle’s logic.config.yml values. Laravel prefers .env variables (e.g., MATOMO_SITE_ID=1).DependencyInjection/Configuration.php to support environment variables (if adapting).{{ piwik_code() }} with @matomo and ensure Blade’s escaping rules match Twig’s.Phase 1: Spike (2 days)
Phase 2: Integration (3 days)
Phase 3: Deprecation (Optional)
How can I help you explore Laravel packages today?