Skip to content

feat(analytics): CWA beacon on production (G B.3.5)#10

Merged
blackbrowed-labs merged 1 commit into
mainfrom
dev
Apr 28, 2026
Merged

feat(analytics): CWA beacon on production (G B.3.5)#10
blackbrowed-labs merged 1 commit into
mainfrom
dev

Conversation

@larsweiser
Copy link
Copy Markdown
Collaborator

Summary

  • Adds the Cloudflare Web Analytics beacon to BaseLayout.astro, gated on both isProduction() (the existing helper from src/lib/env.ts, which checks PUBLIC_ENVIRONMENT === 'production') and a non-empty PUBLIC_CWA_TOKEN.
  • Wires PUBLIC_CWA_TOKEN: ${{ secrets.PUBLIC_CWA_TOKEN }} into the production deploy workflow's Build step env. Not wired into the staging workflow — the production-only gate is enforced both by the deploy-time secret absence and the runtime isProduction() check.
  • Documents the new env var in .env.example.

Closes the CWA-beacon scope item from master plan §4.B.3 that was missed by the G B.3.2 implementation plan. Datenschutz pages already disclose CWA behavior to users (commit 108a5ea); this PR makes the disclosure-vs-reality match.

PUBLIC_CWA_TOKEN (value dd0616e2e6254d0d9c8c608910b2c71a) was added as a GitHub Actions secret on the repo before this commit landed, so the very first production deploy after merge will have the beacon firing.

Test plan

  • Local build with default env → beacon <script> absent (count 0)
  • Local build with PUBLIC_ENVIRONMENT=production PUBLIC_CWA_TOKEN=<test> → beacon present, data-cf-beacon JSON attribute correct
  • Staging deploy → no beacon (token not in staging workflow env)
  • After merge, production deploy → curl -sS https://blackbrowedlabs.com/ | grep beacon.min.js returns the script tag with the real token
  • Cloudflare Web Analytics dashboard → first beacon events appear within minutes of the first production page-view

🤖 Generated with Claude Code

Closes the CWA-beacon scope item from master plan §4.B.3 that was
missed by the G B.3.2 implementation plan. The Datenschutz pages
already disclose CWA behavior to users (Phase B.3.2.b commit
108a5ea); this commit makes the disclosure-vs-reality match.

The beacon is gated on both isProduction() and a non-empty
PUBLIC_CWA_TOKEN — local dev and staging emit nothing, avoiding
non-production traffic pollution in the analytics dashboard.
Verified locally: default npm run build emits no beacon;
PUBLIC_ENVIRONMENT=production PUBLIC_CWA_TOKEN=<test> emits the
script tag with the JSON token attribute as specified.

Master plan §4.B.3 specified the gating as inline
`import.meta.env.PUBLIC_ENVIRONMENT === 'production'`; this commit
uses the existing isProduction() helper from src/lib/env.ts —
identical behavior, idiomatic to the codebase, matches the
isStaging() helper already imported by BaseLayout.

PUBLIC_CWA_TOKEN secret added to the repo's GitHub Actions secrets
ahead of this commit (manual step on Lars's side). The .env.example
documentation block plus the deploy-production.yml env wiring
document the contract for future operators.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@blackbrowed-labs blackbrowed-labs merged commit 2a92db3 into main Apr 28, 2026
2 checks passed
blackbrowed-labs added a commit that referenced this pull request May 12, 2026
Close five Pass 2 backlog rows in one commit; all touch the scripts/
verifier subtree or the verify-cloudflare-facts.yml workflow and all
are cosmetic with zero behaviour change.

- #17 cwa-retention.mjs: fix JSDoc Source URL drift (data-retention ->
  faq) so the header comment matches the sourceUrl constant set in
  G D.10.1.
- #18 cwa-retention.mjs: drop dead NUMBER_WORDS entry `twentyfour`
  (regex never emits the concatenated form) and add `'twenty four'`
  (regex CAN emit the spaced form via `\s-?` alternation).
- #19 dpf.mjs: correct spec section reference from sec 6.3 to the actual
  load-bearing sections sec 3.2 / 3.4 / 9.1 / 9.3.
- #20 verify-cloudflare-facts.yml: PR-body reads naturally for both
  value-change and absent-from-list cases instead of forcing the
  DPF-shaped "went absent" framing onto CWA-style figure shifts.
- #10 scripts/*.mjs: uniform "Run from the project root" docstring
  paragraph in build-headers.mjs, extract-tokens.mjs, and
  run-verifier.mjs (the three top-level scripts surviving after G D.11
  deleted check-cloudflare-facts-freshness.mjs); check modules under
  scripts/checks/ already document the convention via their
  orchestrator. Perms uniform: no +x bit on any .mjs file.

Verifier regression baseline (six MOCK_SCENARIO runs in --dry-run)
re-verified post-edit; statuses unchanged.

Refs: plans/active/pass-2/backlog.md #10, #17, #18, #19, #20
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.

2 participants