Can anyone help tell me why I get this message in ...
# announcements
b
Can anyone help tell me why I get this message in the GrowthBook Dev tool but the SDK configuration tab when logged in say it's connected?
There is: enableDevMode: true, in the GTM code as well.
h
Hi there, what does your SDK implementation look like? Is the SDK otherwise working (able to construct, evaluate a feature, or similar)? Can you check whether
window._growthbook
exists on the page (using chrome dev tools > JS console)?
f
Molly's coworker here - when I do window._growthbook it is undefined but if I do window.growthbook does return some stuff - It is a javascript SDK setting up via GTM
h
Hi, could you share your implementation code? (scrub anything sensitive please, including sdk keys)
f
First tag his this - <script id="growthbook-sdk" src="https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js" defer></script>
Copy code
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
</script>
<script>
  (function() {
    // Wait for the SDK to load before starting GrowthBook
    function startGrowthbook() {
      if (!window.growthbook) return;
      gtag('config', 'G-XXXXXXXXX', {
        'send_page_view': false
      });
      gtag('get', 'G-XXXXXXXXX', 'client_id', function(cid) {
        var gb = new growthbook.GrowthBook({
          apiHost: "<https://cdn.growthbook.io>",
          enableDevMode: true,
          clientKey: "sdk-XXXXXXXXXXXXXXXX",
          // TODO: Add decryptionKey if using encryption
          attributes: {
            id: cid// TODO: Read user/device id from a cookie/datalayer
          },
          trackingCallback: function(experiment, result) {

            gtag("event", "experiment_viewed", {
              event_category: "experiment",
              experiment_id: experiment.key,
              variation_id: result.variationId,
            });
            // TODO: track experiment impression
          }
        });
        gb.loadFeatures({ autoRefresh: true });

        // TODO: Instrument DOM with AB test logic
      });
    }
    if (window.growthbook) {
      startGrowthbook();
    } else {
      window.addEventListener("load", startGrowthbook);
    }
  })();
</script>
h
A few things we can try to debug our way through... 1. Comment out the line
if (!window.growthbook) return;
and see whether it works afterwards. 2. put some console logging before and after
gtag('get', 'G-XXXXXXXXX', 'client_id', function(cid) {
to see whether (A) you're getting into the
startGrowthbook()
function and (B) the gtag client_id lookup is working.
f
I went ahead and console logged the hell out of it - It does not seem to be getting in to the startgrowthbook() function at all. It gets to the else statement on the bottom there and that seems to be where it dies.
h
GTM configurations are notoriously tricky for getting the timing of events working correctly (i.e.: load SDK library, load page, instantiate SDK when ready). Looks like the base case for whatever reason is not working for you guys. Not pretty, but to get over this hurdle we can try something like this to "poll" for
window.growthbook
being ready:
Copy code
if (window.growthbook) {
      startGrowthbook();
    } else {
      setTimeout(startGrowthbook, 100);
    }