jeffersongoncalves / laravel-cloudflare-web-analytics
Cloudflare Web Analytics for Laravel: inject the tracking script in your Blade layouts, with the settings stored in the database via spatie/laravel-settings.
Package info
github.com/jeffersongoncalves/laravel-cloudflare-web-analytics
pkg:composer/jeffersongoncalves/laravel-cloudflare-web-analytics
Fund package maintenance!
Requires
- php: ^8.2|^8.3|^8.4
- laravel/framework: ^12.61.1|^13.12.0
- spatie/laravel-package-tools: ^1.14.0
- spatie/laravel-settings: ^3.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.27
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.7.4|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-10 19:49:39 UTC
README
Laravel Cloudflare Web Analytics
Add Cloudflare Web Analytics — privacy-first, cookie-free analytics from Cloudflare — to your Laravel app. The settings are stored in the database with spatie/laravel-settings, so you can change them at runtime (e.g. from an admin panel) instead of in .env.
For a Filament settings page, use jeffersongoncalves/filament-cloudflare-web-analytics.
Installation
composer require jeffersongoncalves/laravel-cloudflare-web-analytics
Publish and run the settings migration:
php artisan vendor:publish --tag=cloudflare-web-analytics-settings-migrations php artisan migrate
Configuration
$settings = cloudflare_web_analytics_settings(); $settings->token = '0123456789abcdef0123456789abcdef'; $settings->save();
Or through the settings class or the Facade:
use JeffersonGoncalves\CloudflareWebAnalytics\Facades\CloudflareWebAnalytics; use JeffersonGoncalves\CloudflareWebAnalytics\Settings\CloudflareWebAnalyticsSettings; $settings = app(CloudflareWebAnalyticsSettings::class); $value = CloudflareWebAnalytics::getFacadeRoot()->token;
Available settings
| Setting | Type | Default | Description |
|---|---|---|---|
token |
?string |
null |
Your Cloudflare Web Analytics token. The script only renders when it is valid. |
Usage
Add the script to your Blade layout, inside <head>:
@include('cloudflare-web-analytics::script')
Nothing is rendered until the settings are complete, so you can ship the include everywhere and turn Cloudflare Web Analytics on later.
Content Security Policy
When your app sets a CSP nonce through Laravel's Vite (Vite::useCspNonce(), as laravel-security-headers does), every <script> this package renders carries it, so a script-src 'self' 'nonce-{nonce}' policy works without 'unsafe-inline'. Scripts loaded afterwards from the vendor's own CDN still need that host in script-src (and its API in connect-src).
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
