fix(analytics): migrate to native GA4 gtag.js, drop dead UA tag (#855)#1365
Merged
Conversation
Production was firing native GA4 (G-M18PCH55ZP) only indirectly: the inline
Universal Analytics snippet loaded analytics.js, which chain-loaded the GA4
gtag via a console-side "connected site tag" (visible as gtag/js?...&_slc=1
initiated from analytics.js in DevTools). That bridge rides on the retired UA
library and a linkage that lives only in the GA admin console, not in the repo
— so GA4 would silently stop if the legacy machinery is removed.
Replace the UA analytics.js/UA-79723676-1 snippet in base.html with the
official native gtag.js snippet for G-M18PCH55ZP. GA4 now loads directly,
version-controlled, with no dependency on the deprecated UA path. Keeps the
{% if debug %} gate (prod-only). Removing the UA snippet also kills the chain
trigger, so there is no double-counting.
Bump to 2.16.2.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Production was firing native GA4 (
G-M18PCH55ZP) only indirectly. The inline Universal Analytics snippet loadedanalytics.js, which chain-loaded the GA4gtagvia a console-side "connected site tag" (visible in DevTools asgtag/js?id=G-M18PCH55ZP&…&_slc=1, initiated fromanalytics.js):That bridge rides on the retired UA library plus a linkage that lives only in the GA admin console, not in the repo — so GA4 would silently stop collecting if the legacy machinery is removed (or if someone deletes the obviously-dead UA snippet). This is the code side of #855, which originally "shipped GA4" purely via the console with no code change.
Change
website/templates/website/base.html— replace the UAanalytics.js/UA-79723676-1snippet with the official nativegtag.jssnippet forG-M18PCH55ZP. GA4 now loads directly, version-controlled, with no dependency on the deprecated UA path. Keeps the{% if debug %}gate (prod-only).makeabilitylab/settings.py— bump2.16.1→2.16.2.No double-counting: removing the UA snippet kills the chain trigger, so only the direct gtag fires.
Verification
-test/local (GA4 is gated off whenDEBUG=True— expected).G-M18PCH55ZP→ thegtag/jsrequest's Initiator should be(index)directly, notanalytics.js. GA4 Realtime should still show traffic.Follow-up (not in this PR)
🤖 Generated with Claude Code