blue-exabyte-67168
07/31/2023, 3:21 PMclientId
or userId
as an attribute when integrating with the sdk: https://docs.growthbook.io/guide/GA4-google-analytics#sdk-integration-for-ga4
I haven't set either of these attributes, yet everything seems to be working already. With a very simple test experiment, I can see the data from GA4 reflected in the growthbook experiment analysis. Am I missing something, or is it true that setting clientId
or userId
is not required in all cases?better-magician-65629
07/31/2023, 7:03 PMblue-exabyte-67168
07/31/2023, 7:29 PMbillions-xylophone-11752
07/31/2023, 7:58 PMblue-exabyte-67168
07/31/2023, 8:13 PMbillions-xylophone-11752
07/31/2023, 8:15 PMfeature-key
plus the attribute you select in the Assign value based on attribute
dropdown when creating the experiment rule (screenshot below) - and we recommend using the clientId
or userId
so that a user doesn't get bucketed into different variations across visits.
When you're initializing the GrowthBook SDK, are you defining any attributes?blue-exabyte-67168
07/31/2023, 8:43 PMid
and then using that for "Assign value based on attribute"userId
in GA, but it seems to serve a similar purpose from what I understand.clientId
or userId
would, but I'd just like to confirm my understanding.billions-xylophone-11752
08/01/2023, 6:52 PMid
persists between sessions. I do want to double check with some others on the team to make sure there won't be any issues with the experiment analysis long-term. Doing that now.blue-exabyte-67168
08/01/2023, 6:55 PMid
does persist, for the record.billions-xylophone-11752
08/01/2023, 7:13 PMblue-exabyte-67168
08/01/2023, 7:17 PMbillions-xylophone-11752
08/01/2023, 7:19 PMid
field into the trackingCallback and tracking your metrics with the id
as well. That way you're always comparing like for like.blue-exabyte-67168
08/01/2023, 7:59 PMbillions-xylophone-11752
08/01/2023, 8:00 PMblue-exabyte-67168
08/01/2023, 8:01 PMsparse-island-75978
09/07/2023, 1:19 PMuser_pseudo_id
and user_id
with gb_user_id
there?
https://docs.growthbook.io/guide/GA4-google-analytics#generating-your-own-id
<script>
(function() {
// Wait for the SDK to load before starting GrowthBook
if (window.growthbook) {
startGrowthbook();
} else {
document.querySelector("#growthbook-sdk").addEventListener("load", startGrowthbook);
}
function startGrowthbook() {
if (!window.growthbook) return;
const getUUID=()=>{let $="gbuuid",e=()=>window.crypto.randomUUID?window.crypto.randomUUID():"10000000-1000-4000-8000-100000000000".replace(/[018]/g,$=>($^crypto.getRandomValues(new Uint8Array(1))[0]&15>>$/4).toString(16)),t=$=>{let e=`; ${document.cookie}`.split(`; ${$}=`);if(2===e.length)return e.pop().split(";").shift()},r=($,e)=>{var t=new Date;t.setTime(t.getTime()+3456e7),document.cookie=$+"="+e+";path=/;expires="+t.toGMTString()};if(t($))return t($);let i=e();return r($,i),i};
let gbuuid = getUUID();
let gb = new growthbook.GrowthBook({
apiHost: "<https://cdn.growthbook.io>",
clientKey: "sdk-abcd1234",
// TODO: Add decryptionKey if using encryption
attributes: {
id: gbuuid
//add any other attributes here
},
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,
});
}
});
// TODO: Instrument DOM with AB test logic
gb.loadFeatures().then(function() {
// if you want to do anything after GB loads
});
}
})();
</script>
billions-xylophone-11752
09/12/2023, 11:16 AMsparse-island-75978
09/12/2023, 11:22 AMbillions-xylophone-11752
09/12/2023, 1:36 PMgbuuid
, so long as it's persisted as a cookie. That gbuuid
will map to the user_psuedo_id
and user_id
, so there won't be any issue.
Of course, you can always create a new Identifier Type
in GrowthBook for gbuuid
and then build an Experiment Assignment Query around that, but it's not necessary.sparse-island-75978
09/12/2023, 2:15 PMgb_user_id
or gbuuid
? According to your docs ga4 param key is gb_user_id
billions-xylophone-11752
09/12/2023, 2:18 PMgb_user_id