Google Analytics with Astro
Most sites have GA4 installed. Fewer have numbers anyone trusts. I clean up the container, define the events that matter and make sure consent and performance are handled deliberately.
Google Analytics at a glance
- What I do
- GA4 and Tag Manager set up on an Astro site with clean events, consent behavior and performance-conscious loading.
- Typical setup
- Adds 2–4 days
- How it is bought
- Part of a migration scope, or a Continuous development request once the site is yours
- Category
- Analytics and data
Setup
How I set up Google Analytics
The setup starts with measurement decisions, not scripts. What counts as a conversion? Which events will someone actually read six months from now? Which tags are still needed and which are leftovers from old campaigns?
I usually prefer Tag Manager once a site needs more than basic measurement, because it keeps marketing tags in one auditable place and avoids republishing the site for every pixel change. That only works if the container is disciplined. A messy container is just hidden technical debt.
Consent is part of the measurement architecture, not an afterthought. Google Consent Mode needs the right default state before measurement begins and an update when the visitor makes a choice. I check that behavior in Tag Assistant rather than assuming it: that tags fire when they should, stay quiet when they should and do not block the page from loading well.
The deliverable is not an installed tag. It is a measurement setup where the browser, the consent layer and the CRM tell the same story.
How the handoff works
- 01
Consent
Permission state is known
- 02
Tag
GA4 loads correctly
- 03
Pageview
Context and campaign arrive
- 04
Conversion
The right events fire
Key handoff
- 05
Verify
Conversions checked against CRM records
Why this is the key handoff
A tag that fires is not a number you can use. A pageview in GA4 only proves the tag fired. I check that consent, attribution and conversions survive the whole journey and reconcile with what happened downstream.
Included
What gets connected
-
GA4 directly, through Tag Manager, or through the agreed tag architecture
-
A short list of conversion and engagement events
-
Form submissions, outbound clicks and campaign attribution
-
Consent Mode behavior connected to the banner
-
Redirect and UTM handling across the site
Before you add it
What to watch out for
- 01
A checkout or booking on another domain can break attribution
Without cross-domain measurement and the referral exclusions to go with it, a visitor who leaves for a payment processor or a scheduler comes back looking like new referral traffic. The conversion survives and the campaign that produced it is obscured, which is a configuration problem rather than something inevitable.
- 02
An inline form success is not a destination page
For a form that swaps in a success state without navigating, so a conversion configured as a destination never fires. It is tracked as an event on the successful submission instead, and the difference is invisible until the report is empty.
- 03
The container is where third-party scripts accumulate
GA4 itself is small. Tags added through a container bypass the usual development workflow, so old campaign pixels, a second analytics tool and heavy vendor scripts outlive anybody's memory of why they were added. Tag Manager changes need the same ownership and review as other site changes.
More tools
Keep exploring
-
Segment
Send one event stream into the tools that need it, with consistent naming, a shared identity plan and destinations chosen deliberately.
Adds 3–6 days
-
Airtable
Keep content operations in Airtable and render the website in Astro, with field mapping, rebuild triggers and clear publishing status.
Adds 3–6 days
-
PostHog
Connect Astro to PostHog so marketing visits, signup behavior and product activation can be read as one funnel.
Adds 2–4 days
Let me plan your next step.
I can scope a migration. Send a brief and I will reply by email with next steps.