Skip to main content

Analytics

FilamentFlow is a powerful tool, and it's important to understand how your users are interacting with it, however, it is annoying to add global tracking snippets to your application when using Laravel Filament!

Enabling Google Analytics

FilamentFlow supports Google Analytics out of the box. To enable Google Analytics, just enable it and add your tracking ID in the config/filament-flow.php file or the .env file.

config/filament-flow.php
'google_analytics' => [
'enabled' => env('GOOGLE_ANALYTICS_ENABLED', true),
'id' => env('GOOGLE_ANALYTICS_ID', ''),
],
.env
GOOGLE_ANALYTICS_ENABLED=true
GOOGLE_ANALYTICS_ID=UA-XXXXXXXX-1

Using Other Analytics Providers

You could hack around a bunch of providers, or you could just edit the contents of resources/views/partials/googleAnalytics.blade.php to include your tracking snippet. This file is included in the public.blade.php layout file, so it will be included on every page of your application automatically.

resources/views/partials/googleAnalytics.blade.php
@if( config('filament-flow.google_analytics.enabled') && config('filament-flow.google_analytics.id') )
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config('filament-flow.google_analytics.id') }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ config('filament-flow.google_analytics.id') }}');
</script>
@endif