https://www.growthbook.io/ logo
#announcements
Title
# announcements
b

blue-exabyte-67168

07/31/2023, 3:21 PM
I am attempting to use GA4 (via BigQuery) as a data source for experiment analysis. The documentation says to set
clientId
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?
b

better-magician-65629

07/31/2023, 7:03 PM
i'm going to ping someone on the team who's worked on this to get an answer for you
b

blue-exabyte-67168

07/31/2023, 7:29 PM
thank you!
b

billions-xylophone-11752

07/31/2023, 7:58 PM
Hey Brooks! Are the experiment results you're analyzing from an experiment from a past experiment you ran before using GrowthBook, or are you bucketing users via one of the GrowthBook SDKs?
b

blue-exabyte-67168

07/31/2023, 8:13 PM
It was for a test experiment that used a Growthbook SDK
👍 1
b

billions-xylophone-11752

07/31/2023, 8:15 PM
Our hashing algorithm uses a combination of the
feature-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?
Screen Shot 2023-07-31 at 4.15.36 PM.png
b

blue-exabyte-67168

07/31/2023, 8:43 PM
Yes, we have our own internal user id which we are setting as an attribute called
id
and then using that for "Assign value based on attribute"
We don't set this as the
userId
in GA, but it seems to serve a similar purpose from what I understand.
@billions-xylophone-11752 just a nudge in case this has fallen off your radar since yesterday. It's sounding like I'm okay since our internal ID is playing the same role as
clientId
or
userId
would, but I'd just like to confirm my understanding.
b

billions-xylophone-11752

08/01/2023, 6:52 PM
@blue-exabyte-67168 Sorry! I'm fairly confident that you're fine from a bucket perspective, so long as the
id
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.
b

blue-exabyte-67168

08/01/2023, 6:55 PM
Thank you!
The
id
does persist, for the record.
b

billions-xylophone-11752

08/01/2023, 7:13 PM
@blue-exabyte-67168 I got some feedback from others on the team that there is no problem with using any ID you want, so long as it can persist across sessions and it is what is linked to your metrics and used as your identifier type in GrowthBook.
b

blue-exabyte-67168

08/01/2023, 7:17 PM
Okay makes sense, appreciate the help!
b

billions-xylophone-11752

08/01/2023, 7:19 PM
So you'll want to make sure that you're passing the your
id
field into the trackingCallback and tracking your metrics with the
id
as well. That way you're always comparing like for like.
b

blue-exabyte-67168

08/01/2023, 7:59 PM
Right, that looks to be what we are doing
b

billions-xylophone-11752

08/01/2023, 8:00 PM
Cool - that should be a-ok then!
b

blue-exabyte-67168

08/01/2023, 8:01 PM
Nice, thanks again!
s

sparse-island-75978

09/07/2023, 1:19 PM
@agreeable-notebook-26033 @blue-exabyte-67168 Hey guys! Hope you are doing well, just wanted to clarify one point - should I update assignment query when using my own random hash for id attribute? Should i replace
user_pseudo_id
and
user_id
with
gb_user_id
there? https://docs.growthbook.io/guide/GA4-google-analytics#generating-your-own-id
Copy code
<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>
@white-fireman-22476 Hey man, can you please check my question above, it’s related to the thread where we had a discussion, thank you in advance!
@white-fireman-22476 @agreeable-notebook-26033 Hey guys, kind reminder
b

billions-xylophone-11752

09/12/2023, 11:16 AM
@sparse-island-75978 Hopping in here - I'm fairly confident it is not necessary, but I am double checking with someone more familiar with GA4. I'll follow up shortly.
s

sparse-island-75978

09/12/2023, 11:22 AM
@agreeable-notebook-26033 Thank you!
b

billions-xylophone-11752

09/12/2023, 1:36 PM
@sparse-island-75978 - I was able to confirm with others - it is not necessary to update the experiment assignment queries if you're using the
gbuuid
, 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.
s

sparse-island-75978

09/12/2023, 2:15 PM
@agreeable-notebook-26033 Thank you! Just wanted to clarify - should I send it as
gb_user_id
or
gbuuid
? According to your docs ga4 param key is
gb_user_id
b

billions-xylophone-11752

09/12/2023, 2:18 PM
gb_user_id
15 Views