mysterious-hospital-86275
02/09/2024, 4:52 AMbillions-xylophone-11752
02/09/2024, 1:32 PMExperiment Assignment
queries need some customization - we make an attempt to build the default queries, but they don't work all of the time.
Specifically, with BigQuery and GA4, the issue is with the FROM
clause in the Experiment Assignment queries - you need to update the dataset in the from query (by default it's my_dataset
.
To do this, you can go to the data source and edit the Experiment Assignment Queries - when editing, there is a test functionality to know if the updates work as expected.mysterious-hospital-86275
02/12/2024, 3:41 AMbillions-xylophone-11752
02/12/2024, 11:57 AMtrackingCallback
at all? It sounds like whenever a feature flag/experiment is evaluated, nothing is actually writing to BigQuery.
For example, instantiating the GrowthBook object, you'll need to do something like:
trackingCallback: function(experiment, result) {
// track with GA4, for example:
gtag("event", "experiment_viewed", {
event_category: "experiment",
experiment_id: experiment.key,
variation_id: result.variationId,
gb_user_id: gbuuid,
});
}
Here is a full how-to on integrating GrowthBook with GA4. We have a section on how to integration the SDK here.mysterious-hospital-86275
02/12/2024, 12:02 PMfunction startGrowthbook() {
if (!window.growthbook) return;
console.log(window.growthbook,"window.growthbook")
var exp = dataLayer[0].all_experiment_objects[0]
window.gbuuid = window.readCookie('_ga');
window.gb = new growthbook.GrowthBook({
apiHost: "<https://cdn.growthbook.io>",
clientKey: "sdk-XXXXXXXXXXXX",
// TODO: Add decryptionKey if using encryption
attributes: {
id: gbuuid,
expValue:dataLayer[0].optimize_all_experiment_experiment_id
//add any other attributes here
},
debug:true,
enableDebugMode:true,
enableDevMode: true,
subscribeToChanges: true,
trackingCallback: function(experiment, result) {
// track with GA4, for example:
console.log("experiment-result",experiment,result)
dataLayer.push( {
event:'experiment_viewed',
type:'experiment',
experiment_id: experiment.key,
variation_id: result.variationId,
gb_user_id: window.gbuuid,
} )
}
});
window.gb.loadFeatures();
// TODO: Instrument DOM with AB test logic
//window.gb.loadFeatures().then(function() {
// if you want to do anything after GB loads
Object.keys(window.gb.getFeatures()).map(function(ele){
console.log(ele+" variation assigend -> "+window.gb.getFeatureValue(ele, "fallback"))
})
//});
}
billions-xylophone-11752
02/12/2024, 12:05 PMsdk-XXXXXXX
- I take it that was just for copy and pasting the code snippet?
If this is installed on a public site, you're welcome to send me the link and I can look at it further. You're welcome to DM it to me if you feel more comfortable.mysterious-hospital-86275
02/12/2024, 12:06 PMmysterious-hospital-86275
02/12/2024, 12:07 PMmysterious-hospital-86275
02/12/2024, 12:07 PMbillions-xylophone-11752
02/12/2024, 12:35 PMwindow.readCookie
is not a function. So I'm not sure window.gbuuid
is being set correctly.
2. It looks like you have two accounts. and a few different data sources in each account, but for each one, the userIdTypes
I see are userId
and anonymous_id
, but you're not passing in a user_id
attribute, just an id
attribute. So when we query the BigQuery events_*
table(s) we're looking for the user_id
column that doesn't exist.
A few things to do, can you confirm if a value is being set for window.gbuuid
? You will either want to update the trackingCallback
to pass in user_id
instead of gb_user_id
or update the Experiment Assignment Queries
so that instead of looking for user_id
it looks for gb_user_id
.
And as a health check, if you have access to BigQuery, just checkout some recent events
tables, and see if there are any events fired for 'experiment_viewed'. I suspect there are events, so we just need to polish the queries GB is using to make sure we're looking for the correct columns.billions-xylophone-11752
02/12/2024, 12:35 PMmysterious-hospital-86275
02/12/2024, 2:48 PMuser_id
and anonymous_id
.
3. But what should be the value of these two attributes is it different from id that i am currently sending as attributes.
4. Also i tried and didn't found any event with experiment_viewed in big query
5.billions-xylophone-11752
02/12/2024, 3:20 PMtrackingCallback: function(experiment, result)
{
// TODO: track experiment impression
dataLayer.push({
'event': 'experiment_viewed',
'user_id': gbuuid,
'experiment_id': experiment.key,
'variation_id': result.variationId,
});
}
With regards to the attributes, when you're passing in attributes, those are attributes that you can use to define experiment rules: e.g. if county is 'US' show experiment.
Then, inside the trackingCallback, GB defaults to using user_id
. This trackingCallback call essentially adds a row to BigQuery that says "user123, saw variation 1, of this experiment, at this date/time". GB is able to use that info to build the experiment analysis.
Currently, we're looking for the user_id
column in BigQuery, and we don't see it.
So, while you can use different attributes for setting attributes and in the trackingCallback, it's best practice to use the same one (its just easier).
If you use the trackingCallback that I pasted above, you won't have to update any queries in GrowthBook.
• 4. Hmm... that's odd. Sometimes GA4 takes 24 hours to sync data to BigQuery, but I'm guessing that's not the issue here. Can you confirm the Service Account
has the following permissions?
• BigQuery Data Viewer
• BigQuery Metadata Viewer
• BigQuery Job Usermysterious-hospital-86275
02/12/2024, 3:33 PMbillions-xylophone-11752
02/12/2024, 3:39 PMtrackingCallback
accordingly. We don't offer a hosted data solution where we handle writing the data to our own databases. One of our core principles is not building any vendor lock-in into our product, and this warehouse native approach reduces the chances of your user's PII data ever leaving your control.mysterious-hospital-86275
02/13/2024, 6:47 AMbillions-xylophone-11752
02/13/2024, 12:03 PMcountry === "CA"
to get variation 1?
That is not possible with an experiment as the bucketing of users wouldn't be random, and therefore the analysis wouldn't be accurate. When creating an experiment, you can target by attribute, so you can say, only add users to the experiment if their country === 'CA' - and then of those users, GrowthBook will assign them a variation.
If you do need to force a certain variation for a user, you can use feature flags with force rules. This allows you to say "show variation 1 to users if their country is 'CA'. This is different from an experiment where GrowthBook will randomly bucket the users. But in that case, since GrowthBook isn't doing the targeting, the trackingCallback isn't fired.mysterious-hospital-86275
02/14/2024, 6:48 AMSELECT count(distinct(user_id)) FROM `trending-pages-edi.analytics_343679482.events_*`,UNNEST(event_params) AS event_param where event_name = 'experiment_viewed' and
event_param.key = 'experiment_id' AND REGEXP_CONTAINS(event_param.value.string_value, r'shoppageexp2')
billions-xylophone-11752
02/14/2024, 2:22 PMmysterious-hospital-86275
02/14/2024, 2:24 PMbillions-xylophone-11752
02/14/2024, 3:13 PMexp_
mysterious-hospital-86275
02/14/2024, 3:17 PMexp_19g61olsbcryvz
billions-xylophone-11752
02/14/2024, 3:47 PMmysterious-hospital-86275
02/14/2024, 3:49 PMbillions-xylophone-11752
02/14/2024, 4:04 PMmysterious-hospital-86275
02/14/2024, 4:23 PMmysterious-hospital-86275
02/14/2024, 4:23 PMbillions-xylophone-11752
02/14/2024, 6:25 PMnull
user_id values
3. The experiment assignment query doesn't contain the regex
matching clause like the query you shared
4. The experiment analysis query (which is a larger query that contains the experiment assignment subquery) runs by default every 6 hours (though, you can always manually refresh it via the GrowthBook UI), so its possible that the 6 hour delay could be responsible for the difference.
Again, without having access to the data, it's hard for me to pinpoint what could be causing the difference.mysterious-hospital-86275
02/15/2024, 3:38 AMbillions-xylophone-11752
02/15/2024, 4:10 PMmysterious-hospital-86275
02/15/2024, 4:26 PMbillions-xylophone-11752
02/15/2024, 4:31 PMmysterious-hospital-86275
02/15/2024, 5:06 PMmysterious-hospital-86275
03/06/2024, 12:00 PMadventurous-finland-60749
03/18/2024, 11:30 AM