Skip to content

feat(website): load Cloudflare Web Analytics beacon on production docs (#692) - #695

Merged
tbolis-at-mulesoft merged 1 commit into
developfrom
feat/692-cloudflare-web-analytics-beacon
Sep 29, 2026
Merged

tbolis-at-mulesoft merged 1 commit into
developfrom
feat/692-cloudflare-web-analytics-beacon

Conversation

@tbolis-at-mulesoft

Copy link
Copy Markdown
Collaborator

Loads the cookie-less Cloudflare Web Analytics beacon on the production docs site so documentation usage can be measured (tracked end to end in Donkey-Development-Kit/donkey-development-kit-metrics#19).

The beacon is gated on a build-time public site token. website/lib/analytics.mjs returns the script attributes only when NEXT_PUBLIC_CF_WEB_ANALYTICS_TOKEN is a 32-character hex token; an absent or malformed value ships no beacon, so local, preview, and unconfigured builds stay analytics-free. The Pages workflow supplies the token from the repository variable CF_WEB_ANALYTICS_TOKEN (it is public config, not a secret). CI now runs the gate's unit tests (npm test), and website/README.md documents the setup.

The beacon sets no cookies and the site stores nothing about visitors; aggregate counts are pulled server-side by the metrics repo.

Post-deploy steps

  1. In Cloudflare, add the docs hostname under Web Analytics (manual JS snippet setup) and copy the site token.
  2. Add the repository variable CF_WEB_ANALYTICS_TOKEN (Settings > Secrets and variables > Actions > Variables).
  3. Re-run the docs deploy workflow and confirm static.cloudflareinsights.com/beacon.min.js loads on the published site.
  4. To turn analytics off, delete the variable and redeploy.

Closes #692

#692)

Render the cookie-less beacon from the root layout only when the build
receives a well-formed 32-hex NEXT_PUBLIC_CF_WEB_ANALYTICS_TOKEN, supplied
by the Pages workflow from the CF_WEB_ANALYTICS_TOKEN repository variable.
Local and unconfigured builds ship no analytics. The gate is unit-tested
with node --test and runs in the docs CI job.

Refs Donkey-Development-Kit/donkey-development-kit-metrics#19

Co-authored-by: Cursor <cursoragent@cursor.com>
@tbolis-at-mulesoft
tbolis-at-mulesoft merged commit 9adf3f0 into develop Sep 29, 2026
13 checks passed
@tbolis-at-mulesoft
tbolis-at-mulesoft deleted the feat/692-cloudflare-web-analytics-beacon branch September 29, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add production-only Cloudflare Web Analytics beacon to the docs site

1 participant