Consent Management for A/B Testing

All OneTrust and consent‐related logic for A/B testing lives here.

1. Which Events to Listen For

  • Listen to OneTrustGroupsUpdated and visitorConsentCollected.
    • Only fire handleTestExpose when the C0003 group is present.
    • If you use a different consent provider, update the event names accordingly.
  • In GTM, require consent for:
    • ad_storage
    • analytics_storage
    • personalization_storage
  • When consent is denied, block all GA4 tags and A/B exposure events.

3. Preview vs Production

  • Shopify’s consent banner may only appear in production.
  • For OneTrust QA in staging:
    • Set PUBLIC_ONETRUST_DATA_DOMAIN_SCRIPT in your .env.
    • Use a permanent staging URL and test scripts to validate flows.

4. Expected Behaviors

  • No consent
    • handleTestExpose must not fire.
    • No view_experiment events in GTM or GA4.
  • Consent granted
    • view_experiment appears in GTM Debug Mode and GA4 DebugView.
    • Experiment exposure data pushes to window.dataLayer.
  • Consent revoked mid-session
    • Stop sending view_experiment events immediately.
  • BigQuery
    • If consent was granted, event appears in BigQuery within 24 hours.
    • If denied, no experiment data is stored.

5. Quick Code Snippet

useEffect(() => {
  function onConsentUpdate(evt: any) {
    const hasFunctional = evt.detail.groups.includes('C0003');
    setHasUserConsent(hasFunctional);
  }
  window.addEventListener('OneTrustGroupsUpdated', onConsentUpdate);
  return () => window.removeEventListener('OneTrustGroupsUpdated', onConsentUpdate);
}, []);

Was this page helpful?