Hey :wave: We're hitting an SRM on a URL Redirect ...
# ask-questions
b
Hey đź‘‹ We're hitting an SRM on a URL Redirect experiment and want a sanity check on whether our
trackingCallback
is wrong or we're hitting a known limitation. Setup: Astro static site, GA4 loaded via GTM (deferred),
@growthbook/growthbook
client-side, bucketing on
deviceId
. 3 variations (control + 2 redirects). Prod (N=2048, p<0.001): Control 47.66% / Var1 25.34% / Var2 27%. Variations losing ~22% of expected exposures. Already ruled out: local simulation (~2000 fresh sessions, capturing every GA4 request) shows balanced bucketing, exactly 1 event per session, no double-fire, no destination re-evaluation. SDK looks clean in isolation. Our hypothesis: because GA4 is GTM-deferred,
gtag.js
sometimes isn't ready before GrowthBook fires the redirect (within 2s
maxNavigateDelay
). The queued
experiment_viewed
sits in
dataLayer
, page unloads, event lost. Control has no deadline, so it always delivers. Implementation (per docs' async-callback +
transport_type: 'beacon'
pattern):
Copy code
trackingCallback: (experiment, result) => {
  const attrs = gb.getAttributes() as Record<string, string>
  const isRedirectVariation = !!(result.value as { urlRedirect?: string } | undefined)?.urlRedirect

  if (isRedirectVariation) {
    return new Promise<void>((resolve) => {
      gtag('event', 'experiment_viewed', {
        transport_type: 'beacon',
        event_category: 'experiment',
        experiment_id: experiment.key,
        variation_id: result.variationId,
        gb_user_id: attrs.userId,
        gb_device_id: attrs.deviceId,
        event_callback: resolve,
      })
    })
  }

  return new Promise<void>((resolve) => {
    gtag('event', 'experiment_viewed', {
      event_category: 'experiment',
      experiment_id: experiment.key,
      variation_id: result.variationId,
      gb_user_id: attrs.userId,
      gb_device_id: attrs.deviceId,
      event_callback: resolve,
    })
  })
},
Question: is something wrong here, or is
transport_type: 'beacon'
known to be unreliable with GTM-deferred GA4? If the latter — what do you recommend for client-side redirect experiments when Edge Worker SDK isn't an option? Thanks!
f
Hi Dalius.
there can be a race condition for URL redirect experiments, which can case a bias towards control.
There are two good ways around this
1. Use our Edge/CDN SDK 2. Use a script which can fire the event on both the control and destination page: https://gist.github.com/Auz/743dcb8d7aff0acf585e51fbbd7ff1ed
b
thanks thankyou 🙏
Hey, I have one more question regarding your second suggestion. I’ve already implemented the proposed solution, but after more extensive testing, I encountered another issue: the “Multiple Exposures Check” exceeds 1%. 🤔
Should I need to add an additional check to prevent duplicate exposure events for the same experiment/variation pair?
?