brave-army-87438
08/24/2023, 8:05 PMhappy-autumn-40938
08/24/2023, 8:19 PMwindow._growthbook
exists on the page (using chrome dev tools > JS console)?flaky-rain-76756
08/24/2023, 8:23 PMhappy-autumn-40938
08/24/2023, 8:42 PMflaky-rain-76756
08/24/2023, 8:45 PM<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>
happy-autumn-40938
08/24/2023, 9:54 PMif (!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.flaky-rain-76756
08/25/2023, 2:30 PMhappy-autumn-40938
08/25/2023, 5:58 PMwindow.growthbook
being ready:
if (window.growthbook) {
startGrowthbook();
} else {
setTimeout(startGrowthbook, 100);
}