GA4 tag without a rebuild

The Google Analytics measurement id is stored in the platform and fetched by the site at runtime, so changing it never needs a deploy.

What it is

A validated GA4 id set from the SEO settings tab and served by a small public, cacheable config endpoint containing nothing but that id. The analytics beacon fetches it, and if an id is present injects the gtag script with IP anonymisation on. If no id is set, nothing is injected at all.

Also called: google analytics · GA4 measurement id · analytics tag

See it
GA4 tag without a rebuild
Won
34%
Avg cycle
9d
Pipeline
$648k
JanSep
The Settings GA4 field with its validation message, beside the config endpoint's one-key response. Sample data — no customer information appears here.
How it works
  1. 1The setGa4 action validates the id against the G-XXXXXXX pattern before storing it.
  2. 2/api/site-config returns { ga4 } and only ever returns an id that still matches the pattern.
  3. 3The beacon fetches it after load, appends the gtag script, and configures it with anonymize_ip.
  4. 4A fetch failure is swallowed — analytics must never break the page.
Why we built it

Written in the beacon: "GA4 (Keith 08-20): tag id lives in the platform (SEO settings) — injected here so the static pages never need a rebuild to change it." A measurement id hard-coded into static marketing pages makes swapping properties a code change, and the endpoint is deliberately minimal — "Public, cacheable config for the static marketing pages (GA4 id). No secrets."

The problem
  • The measurement id was compiled into static pages.
  • Analytics configuration required a release.
Sound familiar?
What you get
Swap or remove the GA4 property from a settings field
IP anonymisation is on by default
A config failure never affects the page

See it on your own jobs

Twenty minutes, your numbers, no slide deck. We’ll build one of your real buildings in front of you and send you the estimate link at the end — yours to keep either way.

or keep browsing features →