Hey we followed the SDK implementation instruction...
# ask-questions
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>
(function() {
// wait for async load
if (window.growthbook) {
} 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) {
event: 'experiment_impression',
experiment_id: experiment.key,
variant_id: variant.key
@sparse-australia-53384 has opened an issue Close Issue button
Hi, Radek, we'll take a look and follow up with an update as soon as we can.
Hi Radek, I have a few questions and suggestions in order to gain some more info: 1. We'd need to see some logging in order to try to figure out what might be happening. Could you please add console.log() statements in the following places in the code snippet you sent, then once some logs come through, send us the logs? - After the ​`<script>`​ tag to make sure it's loading - Inside the ​`startGrowthbook()`​ function - Right before ​`gb.loadFeatures()`​ - Inside the ​`trackingCallback`​, right before ​`dataLayer.push()`​ 2. Why is ​`user­_id`​ set to "undefined"? 3. Where does the ​`client­_id`​ come from? Are you sure it exists before the function is called? 4. Is the hash ID the client ID? This can be found in the Experiments area of the GrowthBook UI.
In Experiments --> Select the one in question --> 3 vertical dots for more --> Edit --> Assignment Attributes --> Make sure ​`client­_id`​ is there.
Hi August, thanks for getting back to me. 1. GB seems to be loading for me each time I visit the website and the dataLayer contains the callback values. The experiment itself puts a message into console whether it’s C or V1, which also seems to be working - see all attached screenshots. We use GTM, which is embedded before GB code and there is no delay waiting for gtag to get us client or session IDs - we use _ga cookie or a random number on page load. 2.
is set only for signed-in users. Anonymous users do not have a valid user_id 3.
is either a user_id (user signed in) OR _ga cookie (gdpr opt-in) OR random number used through the session 4. yes - the client_id is passed through and set up as an attribute (see screens on the original post)
The experiment has been live for 2 days and here’s yesterdays data
You can see the website here - rentola.at
Hi Radek, thanks for getting back to me in so much detail, I appreciate it! I'll take another look today and follow up here once I have some updates. 😀
Many thanks. Here’s a link to the experiment preview just for reference - https://rentola.at/?at_rentola_test=1
Hi Radek, I wanted to follow up on this thread. Were you able to resolve the issue?
Hi @brief-honey-45610 unfortunately there hasn’t been any progress on this. Out of 100% traffic experiments seem to load only 3-5% of users
cc @agreeable-activity-31366
Hi, Radek - I just wanted to hop in - I've taken a look at your code and it all looks correct. Can you confirm - when you're testing via an incognito browser, are you able to see both variations? Is the issue that very few users are seeing the variation, or is the issue that both variations are being seen, the data indicating who saw which variation just isn't making it into BigQuery? Also, you mentioned that you're using URL targeting. Can you take a screenshot of that URL targeting for me? (You're welcome to DM it to me, if you'd prefer). Something like the screenshot attached. Can you also confirm that you have the "Include visual experiments in endpoint's response" enabled? Info here. We did also recently release a new pre-built script tag - that might be a good route to try and in order to identify if there is something going on with the script you pasted above.
🙏🏻 1
Hi @billions-xylophone-11752 thanks for the pointers. 1. Yes, the experiment seems to be loading at all times in incognito mode. But yeah the data doesn’t seem to flow into GA4 / BigQuery. 2. URL targeting - attached 3. SDK config - attached 4. I have deployed this script on another website using GTM and predefined object - attached. The whole setup is exactly the same. Currently I see a live view of 130 session_start events but only 11 experiment_impressions.
This is very strange. My first suggestion would be to insert a log statement inside of the tracking callback to ensure that it is indeed being fired upon every experiment exposure
@swift-helmet-3648 Not necessary. I can see the dataLayer push in console on each page load.
Could it be something with GA4 then? I'm not sure if I understand correctly but it seems like the GB SDK is working as intended (firing the callback on experiment exposure)
@swift-helmet-3648 the problem is that all previews are firing correctly. GA4 is showing experiment_impression event in live events and debug views but when it comes to the user count we bucket less than 5% of users. The targeting is supposed to target 100% of traffic. Or is the targeting wrong?
The URL targeting is fine (sidenote: we've shipped a new feature in the visual editor to help debug and confirm that your URL targeting is working properly; look for the 'Debug Panel')
Does your experiment have any additional rules like a rollout rule perhaps that is narrowing the targeted traffic?
@swift-helmet-3648 No other targeting rules. Only assignment to client_id and for all sites. I’ve run another listening test on another website where I used a wildcard * instead of the hostname and this setup seems to be working better (around 80% users bucketed in).