aimeos / laravel-analytics-cloudflare
Cloudflare driver for Laravel Analytics Bridge
dev-master
2025-09-12 08:03 UTC
Requires
- php: ^8.2
- aimeos/laravel-analytics-bridge: ~1.0||dev-master
- google/apiclient: ^2.0
This package is auto-updated.
Last update: 2025-09-12 08:06:20 UTC
README
Cloudflare driver for Laravel Analytics bridge.
Cloudflare Web Analytics requires two credentials to query data via the Analytics API:
- siteTag → A unique identifier for your website.
- API Token → An access token that authorizes your app to query the GraphQL API.
1. Find Your siteTag
The siteTag
is generated when you enable Web Analytics for a domain.
- Log in to Cloudflare Dashboard.
- Select your website from the list.
- In the sidebar, go to Analytics → Web Analytics.
- If you haven’t yet enabled Web Analytics, click Enable Web Analytics and follow the setup.
- Cloudflare will show you a JavaScript snippet to embed in your site.
Example:
<script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"token": "abcd1234efgh5678ijkl9012mnop3456", "siteTag": "xyz987654321"}'></script>
- Copy the
siteTag
value from inside thedata-cf-beacon
attribute.
Note: The
siteTag
is unique per domain you configure.
2. Create an API Token
You need a token to access the Cloudflare GraphQL Analytics API.
- Go to your Cloudflare Dashboard → My Profile → API Tokens.
- Click Create Token.
- Choose Create Custom Token.
- Add permissions:
- Account → Analytics → Read
- (If you only want Web Analytics, this scope is enough.)
- Select the account that contains your website.
- Save and copy the generated API Token.
3. Configure in Analytics Bridge
The ./config/analytics-bridge.php
file already contains:
return [ 'default' => env('ANALYTICS_DRIVER'), 'drivers' => [ 'cloudflare' => [ 'siteTag' => env('CLOUDFLARE_SITETAG'), 'token' => env('CLOUDFLARE_TOKEN'), ], /* ... */ ], /* ... */ ];
Add the required key/value pairs to your .env
file:
ANALYTICS_DRIVER="cloudflare"
CLOUDFLARE_SITETAG="..."
CLOUDFLARE_TOKEN="..."