Hello I've been trying to get an A/B test to run o...
# ask-questions
f
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
@swift-helmet-3648 any ideas?
do you see the network request to cdn.growthbook.io ?
f
Yep shows up as sdk-xxxxxx as the name in the network panel right?
s
For the SDK connection in Growthbook, do you have both visual and draft experiments enabled?
f
Yep
s
Perhaps the URL pattern is not configured right. Can you paste it here?
f
tried taking the slash out and replacing it with a wildcard just in case
s
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
What other attributes should I set then beyond just setting the ID?
s
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
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
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
ok cool updated that so it has id in it but still doesn't seem to work
s
Can you confirm you're setting it client-side? From the code you pasted I don't see it happening
f
Copy code
attributes: {
          id: cid
        },
is there
s
Oh, I've never seen it that way before. Okay, that looks good
f
it's in your documentation that way....
If there is another way you suggest I do it let me know
s
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
@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
this is from the visual editor?
s
I believe that's the SDK payload
f
Yep payload from the network panel
s
And how about your GrowthBook Devtools panel, could you provide a screenshot?
f
Screenshot 2023-08-01 at 10.12.37 AM.png
s
Strange. I have to step out briefly let me take a look in a few and get back to you
f
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
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
do you think its the draft status?
s
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
Where is that information?
s
Probably where you're loading the SDK in GTM ... Is it via a
script
tag or something else?
f
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
@flaky-rain-76756 Try adding the
loadFeatures
call after instantiating your GrowthBook object
Copy code
gb.loadFeatures({ autoRefresh: true });
f
Get this man a raise - That was the issue
🙌 1
f
is that something we should adjust in our docs?
s
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
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
Good catch!
f
but I do remember seeing that line of code somewhere else when looking around and didn't think anything of it