Hey we followed the SDK implementation instructions for javascript and embedded the code on the site...
r

Radek Loucka

over 1 year ago
Hey we followed the SDK implementation instructions for javascript and embedded the code on the site. The script loads and a Growthbook instance seems get initiated. We’re currently running a listening test for all of users to see check if the implementation works. The targeting is super simple - we’re using client_id, which is available at the time of the page load and passed into GB during the init. The client_id attribute has been set in Growthbook backend. I used URL targeting for implementation with simple match to include root domain - include ‘domain.com’ However, after looking into the live view in GA4, the trackingCallback seems to be fired only the odd time. When loading the results from BigQuery we get number for 14 users just for yesterday, which is not even a 1% of our daily visitors. When checking the live data in GA4 I can see - e.g. 400 page_views, 50 session_start events but 1 experiment_impression. The site is a SPA so I would expect the experiment_impression to be higher that session_start count. Any idea why this is happening?
<script defer='defer' id='growthbook-sdk' src='<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.js>'></script>
<script>
(function() {
// wait for async load
if (window.growthbook) {
startGrowthbook();
} else {
document.querySelector("#growthbook-sdk").addEventListener("load", startGrowthbook);
}
function startGrowthbook() {
if(!window.growthbook) return;
window.gb = new growthbook.GrowthBook({
apiHost: "<https://cdn.growthbook.io>",
clientKey: "XXXXXXXX",
decryptionKey: "XXXXXXXX",
enableDevMode: false,
subscribeToChanges: true,
attributes: {
id: "1056967161.1698327286",
client_id: "1056967161.1698327286",
user_id: undefined,
signed_in: false,
membership_type: "anonymous"
},
trackingCallback: function(experiment, variant) {
dataLayer.push({
event: 'experiment_impression',
experiment_id: experiment.key,
variant_id: variant.key
});
}
});
gb.loadFeatures();
}
})();
</script>