Skip to content

Analytics: the content security policy blocks every Google Analytics hit #166

Closed

Description

@Luen

What. Google Analytics (#142) probably records nothing. On one page view of /pressure in production (v0.2.8, 8 Nov 2026), the browser blocked every hit that gtag.js sent. Only the gtag/js script loaded.

Request Host Blocked by
page_view (/g/collect) analytics.google.com connect-src
page_view retry (/g/collect) www.google.com connect-src
Google signals (/g/collect) stats.g.doubleclick.net connect-src
audiences pixel (/ads/ga-audiences) www.google.com.au img-src

No request went to *.google-analytics.com, which the policy does allow.

Why.

  • vite.config.ts allows https://*.google-analytics.com, https://*.analytics.google.com and https://*.googletagmanager.com in connect-src.
  • A *. wildcard needs at least one subdomain, so it doesn't match the bare host analytics.google.com.
  • With Google signals on, gtag also sends to www.google.com and *.g.doubleclick.net.

Fix, either:

  • add https://analytics.google.com, https://www.google.com and https://*.g.doubleclick.net to connect-src (Google's CSP guide for GA4 with signals also lists them for img-src; the country-specific ga-audiences pixel can stay blocked); or
  • turn off Google signals in the GA property, and check whether the hits then go to *.google-analytics.com.

Acceptance

  • No CSP errors from gtag on a production page.
  • GA Realtime shows the visit.
  • The e2e CSP check (if any) allows the new hosts.

Follow-up to #142. Part of #74.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginfrastructureCI, workflows and deployment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions