incalculable-elephant-73095
09/25/2023, 5:47 AM<script id="growthbook-sdk" src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js>" defer></script>
<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-1231231231",
// TODO: Add decryptionKey if using encryption
attributes: {
cid: "{{clientId}}" // 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: Instrument DOM with AB test logic
gb.loadFeatures().then(function() {
// NOTE: We may wish to remove `gb.loadFeatures()` and instead manually implement experiment logic
});
}
})();
</script>
window.gtag = window.gtag || function() { dataLayer.push(arguments); };
happy-autumn-40938
09/26/2023, 4:24 AMindex.min.js
script actually load? (check browser network tab)
• does the SDK integration <script> load?
• does startGrowthbook()
actually trigger?
• does the SDK get constructed? (you can check window._growthbook
in your browser console if you add enableDevMode: true
to your constructor)
• do you have a valid experiment that would trigger the callback?
• are you actually triggering the experiment via .isOn()
or similar? I don't see anything in your snippet about this.
Here's another similar thread (with no clear resolution) but outlining the console.log strategy a bit more
https://growthbookusers.slack.com/archives/C01T6PKD9C3/p1692907527349029incalculable-elephant-73095
09/26/2023, 5:35 AMfunction startGrowthbook() {
if (window.growthbook) {
startGrowthbook();
} else {
setTimeout(startGrowthbook, 100);
}
if (!window.growthbook) return;
happy-autumn-40938
09/26/2023, 6:24 AMtrackingCallback()
(I expect nothing is consoled).
I do not see any sort of experiment assignment in your code above, just the placeholder TODO:
// TODO: Instrument DOM with AB test logic
gb.loadFeatures().then(function() {
// NOTE: We may wish to remove `gb.loadFeatures()` and instead manually implement experiment logic
});
See an example of running an experiment at the bottom of this snippet:
https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#strategy-2-flexible-feature-flags-less-performant
gb.loadFeatures().then(function() {
if (gb.isOn("green-button")) {
document.querySelector("#button-1").classList.add("green");
}
});
incalculable-elephant-73095
09/26/2023, 6:54 AMhappy-autumn-40938
09/26/2023, 7:39 AMincalculable-elephant-73095
09/26/2023, 7:40 AMhappy-autumn-40938
09/26/2023, 8:03 AMincalculable-elephant-73095
09/26/2023, 8:12 AMhappy-autumn-40938
09/26/2023, 8:13 AM<https://www.mysite.io/?my-experiment-id=1>
incalculable-elephant-73095
09/26/2023, 8:14 AMhappy-autumn-40938
09/26/2023, 8:16 AMattributes: {
cid: "{{clientId}}" // TODO: Read user/device id from a cookie/datalayer
},
Are you actually using a real userId? You need this attribute to successfully randomly assign a test bucketincalculable-elephant-73095
09/26/2023, 8:19 AMhappy-autumn-40938
09/26/2023, 8:21 AMid
attribute selected in your experiment's Targeting rules (example screenshot using deviceId instead of id)incalculable-elephant-73095
09/26/2023, 8:25 AMhappy-autumn-40938
09/26/2023, 8:33 AMgrowthbook.debug = true
in your code right after constructing the growthbook
SDK instance. Then all experiment assignment log output will be output to your browser console. Hopefully will give some clues as to what's going on.incalculable-elephant-73095
09/26/2023, 1:15 PMtrackingCallback: (experiment, result) => {
// TODO: Use your real analytics tracking system
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key
});
}
});
fresh-football-47124
incalculable-elephant-73095
10/15/2023, 11:18 AMfresh-football-47124
incalculable-elephant-73095
10/16/2023, 7:37 AM