Skip to content

Commit a3102ce

Browse files
Keep traffic quality on consent-loaded Google Analytics
main (#1399) added traffic-quality tagging to the inline GA bootstrap, which this branch replaces with c15t's gtag helper. Install the same wrapper in the helper's onBeforeLoad, after gtag and config are queued and before held page views flush, so every event still carries traffic_quality.
1 parent f2bedd5 commit a3102ce

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎src/utils/consent.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { sentry } from '@c15t/integrations/sentry'
44
import { getClient, setUser } from '@sentry/tanstackstart-react'
55
import { flushPendingGoogleAnalyticsEvents } from '~/utils/analytics/providers/google'
66
import { scarf } from '~/utils/analytics/scarf'
7+
import { TRAFFIC_QUALITY_BOOTSTRAP } from '~/utils/analytics/traffic-quality'
78

89
const GOOGLE_ANALYTICS_ID = 'G-JMT1Z50SPS'
910
// src/server.ts proxies gtag.js and its collect endpoint through /_a.
@@ -40,6 +41,9 @@ export const consentScripts: NonNullable<ConsentRootProps['scripts']> =
4041
// The helper defines gtag and queues consent defaults and config
4142
// here, so page views held since hydration can go out after them.
4243
googleTag.onBeforeLoad?.(info)
44+
// Wraps gtag so every event carries traffic_quality. It must run
45+
// before the held events go out.
46+
new Function(TRAFFIC_QUALITY_BOOTSTRAP)()
4347
flushPendingGoogleAnalyticsEvents()
4448
},
4549
},

0 commit comments

Comments
 (0)