I am running an A/B Test using the google analytic...
# give-feedback
c
I am running an A/B Test using the google analytics cookie as the Assignment Attribute. To my understanding that's all I need todo, and everything appears to be working as it should, but I am seeing the Multiple Exposures Warning as seen in the image below. Could anyone from the team share some possible reasons I am seeing this warning? I am open to answer any clarifying questions.
p
Hmm, I see exactly the same on an a/a test, everything else seems to working correctly. also using the "_ga" cookie value as deviceId in attributes. Also making sure that the _ga cookie is present before initializing GB
I think moving to a separate deviceId cookie for GB solved it for me. The/our GA4 client_id cookie doesn't seem as consistent as expected. Here's my code which I adapted based on code by @fresh-football-47124 that was mentioned here: https://growthbookusers.slack.com/archives/C01T6PKD9C3/p1692118042101769?thread_ts=1692051989.660669&cid=C01T6PKD9C3
Copy code
<script>
const COOKIE_NAME = "gbuuid";
const COOKIE_DAYS = 400; // 400 days is the max cookie duration for chrome

const getUUID = () => {
  
  // use the browsers crypto.randomUUID if set
  const genUUID = () => {
    if(window?.crypto?.randomUUID) return window.crypto.randomUUID();
    let randUUID = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
      (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
    return randUUID;
  }

  const getCookie = (name) => {
    let value = `; ${document.cookie}`;
    let parts = value.split(`; ${name}=`);
    if (parts.length === 2) return parts.pop().split(';').shift();
  }

  // get the existing UUID from cookie if set, otherwise create one and store it in the cookie
  return getCookie(COOKIE_NAME) || genUUID();
}


// GrowthBook usage with GA4:

function setupGrowthBook(){
    if (typeof window.growthbook !== "undefined" && window.growthbook.GrowthBook !== "undefined"  ) {
      let gbuuid = getUUID();
      storeUUID(gbuuid);
      startGrowthbook(gbuuid);
    } else {
        setTimeout(() => {
            setupGrowthBook();
        }, 100);  // waits for 100ms before checking again
    }
}
  
function startGrowthbook(gbuuid) {
  if (!window.growthbook) return;

  const { GrowthBook } = window.growthbook;
  window.gb = new GrowthBook({
    apiHost: "<https://cdn.growthbook.io>",
    clientKey: "sdk-XXXX",
    enableDevMode: true,
    attributes: {
        deviceId: gbuuid
    },
    trackingCallback: (experiment, result) => {
    // TODO: Use your real analytics tracking system
      console.log("Viewed Experiment", {
      experimentId: experiment.key,
      variationId: result.key
    });
    }
  });

  // TODO: Instrument DOM with AB test logic
  gb.loadFeatures().then(function() {
    // if you want to do anything after GB loads
  });
}

function storeUUID(uuid) {

  const setCookie = (value) => {
    var d = new Date();
    d.setTime(d.getTime() + 24*60*60*1000*COOKIE_DAYS);
    document.cookie = COOKIE_NAME + "=" + value + ";path=/;expires=" + d.toGMTString();
  }
  
  setCookie(uuid);
}
  
</script>

<!-- Load GB library and then fire initialization when available -->
<script src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.js>" onload="setupGrowthBook()"></script>
Hope this helps!
🙏🏾 1