Hello I've been trying to get an A/B test to run or even preview in draft mode. I have the SDK setup...
d

Dan Baran

almost 2 years ago
Hello I've been trying to get an A/B test to run or even preview in draft mode. I have the SDK setup through GTM. I made the changes using the visual editor. The SDK does have all the visual experiments turned on. I've gone to the page that the changes were made on - didn't see any changes, I've checked the dev panel tool and it says no experiments. Here is my code snippet from GTM with the api replaced with x's any help would be appreciated on what I need to do to get this running and working.
<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;
      gtag('get', 'G-6GFJGEGDHC', 'client_id', function(cid) {
      var gb = new growthbook.GrowthBook({
        apiHost: "<https://cdn.growthbook.io>",
        enableDevMode: true,
        clientKey: "sdk-xxxxxxxxxxxxx",
        // TODO: Add decryptionKey if using encryption
        attributes: {
          id: cid // TODO: Read user/device id from a cookie/datalayer
        },
        trackingCallback: function(experiment, result) {
          console.log(result);
          analytics.track("Experiment Viewed", {
      experimentId: experiment.key,
      variationId: result.key,
    });
          // TODO: track experiment impression
        }
      });
console.log(gb);
        console.log(gb.experiment);
        console.log(cid);
      // TODO: Instrument DOM with AB test logic
      
      });     
  }
      
  })();
</script>