https://www.growthbook.io/ logo
f

flaky-rain-76756

07/31/2023, 8:38 PM
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.
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;
      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>
f

fresh-football-47124

07/31/2023, 8:43 PM
@swift-helmet-3648 any ideas?
do you see the network request to cdn.growthbook.io ?
f

flaky-rain-76756

07/31/2023, 8:44 PM
Yep shows up as sdk-xxxxxx as the name in the network panel right?
s

swift-helmet-3648

07/31/2023, 8:44 PM
For the SDK connection in Growthbook, do you have both visual and draft experiments enabled?
f

flaky-rain-76756

07/31/2023, 8:45 PM
Yep
s

swift-helmet-3648

07/31/2023, 8:46 PM
Perhaps the URL pattern is not configured right. Can you paste it here?
f

flaky-rain-76756

07/31/2023, 8:47 PM
tried taking the slash out and replacing it with a wildcard just in case
s

swift-helmet-3648

07/31/2023, 8:48 PM
I noticed you aren't setting user attributes in the code you pasted. I think that usually forces the SDK to exit early and potentially ignore experiments.
The URL looks ok 👍
f

flaky-rain-76756

07/31/2023, 8:49 PM
What other attributes should I set then beyond just setting the ID?
s

swift-helmet-3648

07/31/2023, 8:50 PM
It depends on what hashing attribute you've configured for your experiment, but I believe ID is default which should be sufficient to set on the client-side
f

flaky-rain-76756

07/31/2023, 8:54 PM
Kind of lost me on that one - Where would I find the hashing attribute so I can get this sorted out? Or do I not need it since I have the user id?
s

swift-helmet-3648

07/31/2023, 8:55 PM
Ah, it's also called 'Assignment Attribute' ... Navigate to the experiment in GrowthBook and check out the 'Configure' section. You should see something like the following
f

flaky-rain-76756

07/31/2023, 8:57 PM
ok cool updated that so it has id in it but still doesn't seem to work
s

swift-helmet-3648

07/31/2023, 8:58 PM
Can you confirm you're setting it client-side? From the code you pasted I don't see it happening
f

fresh-football-47124

07/31/2023, 8:58 PM
Copy code
attributes: {
          id: cid
        },
is there
s

swift-helmet-3648

07/31/2023, 8:59 PM
Oh, I've never seen it that way before. Okay, that looks good
f

flaky-rain-76756

07/31/2023, 8:59 PM
it's in your documentation that way....
If there is another way you suggest I do it let me know
s

swift-helmet-3648

07/31/2023, 9:04 PM
I'm not sure why you're not getting experiments to the SDK client. Without that we can't begin to debug the visual experiment side (if it's broken) Does the network response from your API host contain experiments in the payload?
The other way would be to call
gb.setAttributes
after init'ing GB. Although in this case I don't think it will change anything
f

flaky-rain-76756

08/01/2023, 2:25 PM
@swift-helmet-3648 Sorry for the delay had to run yesterday but experiments are showing in the network panel - I'm going to clear out all existing running or drafts and cut it down to 1 for the sake of simplicity but if you see anything else let me know
Cleared it out - brought it down to 1 test. Currently in draft. Everything is still acting the same way.
f

fresh-football-47124

08/01/2023, 3:08 PM
this is from the visual editor?
s

swift-helmet-3648

08/01/2023, 3:11 PM
I believe that's the SDK payload
f

flaky-rain-76756

08/01/2023, 3:12 PM
Yep payload from the network panel
s

swift-helmet-3648

08/01/2023, 3:12 PM
And how about your GrowthBook Devtools panel, could you provide a screenshot?
f

flaky-rain-76756

08/01/2023, 3:12 PM
Screenshot 2023-08-01 at 10.12.37 AM.png
s

swift-helmet-3648

08/01/2023, 3:25 PM
Strange. I have to step out briefly let me take a look in a few and get back to you
f

flaky-rain-76756

08/01/2023, 4:04 PM
Might seem like a dumb question but with GTM implementation do I have to code up the test in GTM or am I allowed to use the visual editor?
s

swift-helmet-3648

08/01/2023, 4:04 PM
As long as GTM is loading the SDK, the visual editor should work fine
The trouble is with the SDK at this point. It's not recognizing your experiments for whatever reason. The visual changes aren't entering the picture yet
Taking a deeper look
f

fresh-football-47124

08/01/2023, 4:13 PM
do you think its the draft status?
s

swift-helmet-3648

08/01/2023, 4:13 PM
I've got it working fine locally w/ draft experiments currently. But that's not a definite 'no' either heh
@flaky-rain-76756 Can you confirm what version of the SDK you're running?
f

flaky-rain-76756

08/01/2023, 4:28 PM
Where is that information?
s

swift-helmet-3648

08/01/2023, 4:29 PM
Probably where you're loading the SDK in GTM ... Is it via a
script
tag or something else?
f

flaky-rain-76756

08/01/2023, 4:31 PM
Here is the only other SDK related GTM item beyond that bit of code in the beginning.
Copy code
<script id="growthbook-sdk" src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js>" defer></script>
👍 1
s

swift-helmet-3648

08/01/2023, 5:23 PM
@flaky-rain-76756 Try adding the
loadFeatures
call after instantiating your GrowthBook object
Copy code
gb.loadFeatures({ autoRefresh: true });
f

flaky-rain-76756

08/01/2023, 5:36 PM
Get this man a raise - That was the issue
🙌 1
f

fresh-football-47124

08/01/2023, 5:37 PM
is that something we should adjust in our docs?
s

swift-helmet-3648

08/01/2023, 5:38 PM
It's in our docs, a little easy to miss is all
I've added to our SDK troubleshooting list - which we should definitely add to our docs
f

flaky-rain-76756

08/01/2023, 5:39 PM
Assuming you are asking him but just for information wise I ended up using the GTM docs which doesn't have that in it at all
👀 1
s

swift-helmet-3648

08/01/2023, 5:39 PM
Good catch!
f

flaky-rain-76756

08/01/2023, 5:39 PM
but I do remember seeing that line of code somewhere else when looking around and didn't think anything of it
6 Views