Skip to content

Analytics: let Google Analytics hits through the CSP (#166) - #171

Merged
Luen merged 1 commit into
mainfrom
fix/166-ga-csp
Nov 9, 2026
Merged

Luen merged 1 commit into
mainfrom
fix/166-ga-csp

Conversation

@Luen

@Luen Luen commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Fixes #166. Part of #74.

What

  • vite.config.ts: one GA_HOSTS list feeds both connect-src and img-src. It adds:
    • https://analytics.google.com: a *. wildcard needs a subdomain, so *.analytics.google.com never matched the bare host gtag posts page_view to.
    • https://www.google.com and https://*.g.doubleclick.net: where hits go with Google signals on (Google's CSP guide for GA4 with signals).
    • img-src now uses the same wildcards as connect-src (it listed only www.google-analytics.com / www.googletagmanager.com).
  • The country-specific ga-audiences pixel (www.google.com.au…) stays blocked, as the issue suggests.
  • e2e/pages.spec.ts: a new test checks that the CSP header's connect-src and img-src carry the new hosts.
  • AGENTS.md: the allowed third parties line lists the GA hosts and points to GA_HOSTS.

Checks

  • pnpm lint, pnpm check, pnpm build, pnpm test:e2e (38 passed).

After deploy (acceptance, not checkable here)

  • No CSP errors from gtag in the console on a production page.
  • GA Realtime shows the visit.

🤖 Generated with Claude Code

A `*.` wildcard needs a subdomain, so `https://*.analytics.google.com`
never matched the bare `analytics.google.com` that gtag posts page_view
hits to; with Google signals on, hits also go to www.google.com and
stats.g.doubleclick.net. All were blocked by connect-src.

One GA_HOSTS list now feeds connect-src and img-src (Google's CSP guide
for GA4 with signals). The country-specific ga-audiences pixel stays
blocked. An e2e test checks the header carries the new hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Luen Luen added bug Something isn't working infrastructure CI, workflows and deployment labels Nov 9, 2026
@Luen
Luen merged commit 5edb3f8 into main Nov 9, 2026
6 checks passed
@Luen
Luen deleted the fix/166-ga-csp branch November 9, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working infrastructure CI, workflows and deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analytics: the content security policy blocks every Google Analytics hit

1 participant