https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
b

better-state-55387

06/13/2023, 11:49 AM
Hi! I want to implement GB with GTM, I'm working based on this documentation: https://docs.growthbook.io/guide/google-tag-manager-and-growthbook We are using GA4, and we want to use GA4's data for AB testing. I am not familiar with coding, and I got a bit lost, I would appreciate if you could help 🙂 1. I have a custom html GB SDK tag, including exactly :
Copy code
<script id="growthbook-sdk" src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js>" defer></script>
2. I have a custom html GB Implementation tag as in the documentation (I have only changed the clientKey. )
Copy code
<script>
  (function() {
    // Wait for the SDK to load before starting GrowthBook
    if (window.growthbook) {
      startGrowthbook();
    } else {
      document.querySelector("#growthbook-sdk").addEventListener("load", startGrowthbook);
    }

    function startGrowthbook() {
      if (!window.growthbook) return;
      var gb = new growthbook.GrowthBook({
        apiHost: "<https://cdn.growthbook.io>",
        clientKey: "sdk-abcd1234",
        // TODO: Add decryptionKey if using encryption
        attributes: {
          id: "u1234" // TODO: Read user/device id from a cookie/datalayer
        },
        trackingCallback: function(experiment, result) {
          // TODO: track experiment impression
        }
      });

      // TODO: Instrument DOM with AB test logic
    }
  })();
</script>
I have a few questions: 1. What to put for the id, if I want two kind of user identification? One is GA4's id, AND our own user_id. I found in the documentation that there is a way to add the GA4 id, however I'm unsure where it goes in the code, and not sure how two make 2 identification. 2. If we want to make the AB tests through the UI, in the Visual Editor feature (but with JS) is there anything else, I have to add to this code? Thank you!
Hi @happy-autumn-40938! Could you please have a look on it?
15 Views