Google Analytics on Next.js, Webflow, Framer and Astro
Google Analytics 4 tells you where visitors come from and what they do. For Next.js Google Analytics, and GA4 on Webflow, Framer and Astro, we set it up so the numbers hold up and nothing fires before consent.
Next.js Google Analytics, step by step
In Next.js, load GA4 through the GoogleTagManager component in the root layout and set consent defaults before the container loads, or page views go uncounted or double.
- 01
Create the property and the container
A GA4 property and a Google Tag Manager container for the site.
- 02
Store the ID on the host
Put the container ID in an environment variable on your host, for production and preview builds.
- 03
Add GoogleTagManager to the root layout
Load the container with the GoogleTagManager component from @next/third-parties in the root layout.
- 04
Set consent defaults first
An inline Consent Mode v2 default runs before the container, and your cookie banner updates it.
- 05
Configure GA4 and verify
Set up GA4 and key events inside the container, then check them in GA4’s DebugView before launch.
Webflow Google Analytics, Framer and Astro: the method per platform
The method depends on where your site is built. Here is what we use for Google Analytics on each platform.
Framer
Framer has a Measurement ID field in Site Settings, but it loads GA4 on every visit. For EU audiences we install Google Tag Manager in Framer’s custom code instead and configure GA4 there with Consent Mode v2, so tags wait for the visitor’s choice in the cookie banner.
Framer development Via GTMWebflow
Webflow offers a built-in GA4 field and Google’s site tools app. We usually add Google Tag Manager in the head and body custom code instead, with GA4 and Consent Mode v2 configured in the container, and avoid running both setups at once, which double-counts every page view.
Webflow development Via GTMAstro
We add the GTM snippet in the base layout of the Astro site, with the consent default set before the container loads. Partytown can move tag work off the main thread, though we test it carefully because some tags break in a worker.
Astro development Via GTMNext.js
We use the GoogleTagManager component from @next/third-parties in the root layout, set consent defaults first, and configure GA4 inside the container. Client-side route changes are measured through GA4’s enhanced measurement of browser history, so page views are not missed or doubled.
Next.js developmentWhat teams use it for
Conversion reporting
Demo requests, sign-ups and trial starts tracked as key events, so you see which channels produce them.
Content performance
Which blog posts, docs and landing pages bring people in, and which lead to the next step.
Campaign checks
UTM-tagged ads and emails compared on engaged sessions and conversions, not just clicks.
Common Google Analytics pitfalls
Two installs at once, such as Webflow’s built-in GA4 field plus a GA4 tag in Google Tag Manager, count every page view twice.
A container ID missing from the host’s environment variables means production ships without analytics, and nobody notices for days.
GA4 sets cookies and sends data to Google. In the EU it needs consent; Consent Mode v2 passes the choice to Google and limits what is sent.
Expect gaps: visitors who decline consent, ad blockers and modeled data mean GA4 numbers will not match your CRM one to one.
Each extra tag in the container adds script weight. We keep the container lean and audit it before launch.
What we set up and hand over
Analytics is the baseline of our SEO & AEO work, from $3,000 a month.
- What we set up
- GA4 via Google Tag Manager, Consent Mode v2, key events, Search Console link
- Typical time
- 1–2 days
- Complexity
- Medium
Questions about Google Analytics
Do I need Google Tag Manager for GA4 in Next.js?
What is @next/third-parties?
Why does GA4 count page views twice?
How do I add Google Analytics to Webflow?
Is Google Analytics GDPR compliant?
What events do you set up?
Thomas OldenburgerFounder, design and build leadStill deciding? A 30-minute call answers most of it.
Related integrations and services
Google Tag Manager
One container for all your analytics and marketing tags, with consent rules and version history.
OpenGoogle Search Console
Google’s free tool for indexing status, search queries, sitemaps and technical search errors.
OpenPostHog
Product analytics, session replay and feature flags, with an EU cloud option.
OpenSEO & AEO
Analytics is the baseline for every SEO and AEO engagement.
OpenTechnical SEO
Glossary definition.
Open