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

Radek Loucka

almost 2 years 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>
Hi, is this the right place to get help? I'm working on setting up Growthbook for my company's webs...
j

Justin Medina

about 2 years ago
Hi, is this the right place to get help? I'm working on setting up Growthbook for my company's website. We are using the growthbook-react sdk. I've set up an experiment for an A/B test, and I see users successfully being split 50/50 on the front end via the Chrome Extension. The documentation was great for getting this far. I am having trouble understanding how to set up the connection between our website, GA4, BigQuery, and Growthbook. Please take a look at my progress and help me identify the misconceptions I'm having about how this all works. Connecting our website to GA4 Our website sends the tracking callback to GA4 as stated in the docs:
const growthbook = new GrowthBook({
  apiHost: env.GROWTHBOOK_HOST,
  clientKey: env.GROWTHBOOK_KEY,
  attributes: {
    id: Date.now()
  },  
  trackingCallback: (experiment, result) => {
    // track using GA4
    if ("gtag" in window) {
      window.gtag("event", "experiment_viewed", {
        event_category: "experiment",
        experiment_id: experiment.key,
        variation_id: result.variationId,
      })
    }
  }
As I understand it, this puts a user into the experiment... by sending an event to GA? Also, I'm using
Date.now()
for the
attributes.id
because we only have anonymous users (docs). I'm suspicious of this approach and open to any suggestions for a better path. We also send a tracking event to GA; the event name is "Submit" and the event category is "Lead Form". (Long story short, we are testing if changes to our lead form steps will increase conversion).
// The submit button was clicked
tracker.event('Submit', {
  event_category: 'Lead Form',
})
As I understand it, this is the event we need to use as a Growthbook metric to define whether or not the experiment was successful or not. GA4 to BigQuery I'm very uncomfortable using BigQuery. It's my first time, but I have somebody to help me. I worked through the documentation to set this up with a service account. When I look in the BigQuery dashboard, I see an
events_
table. I didn't put this there. Did Growthbook do this? I feel that this might be a missed opportunity in the documentation for laymen like me; how does my Google Analytics data translate into BigQuery? BigQuery to GrowthBook I'm still learning my way around the Growthbook dashboard, but I've been able to make some progress setting up a Metric to connect to our BigQuery instance. I have a Metric that I'm calling "Lead form submission". As I understand it, the goal here is to Select rows from that
events_
table to find rows where the
event_name
matches my GA4 tracker event.