I am struggling with specifying the required ID at...
# announcements
s
I am struggling with specifying the required ID attributes for A/B testing. Should user view the same variation when he logs out if I specify both id (from db) and deviceId (random hash)? I tested and see that variation is not consistent when id changes but deviceId is same
a
You'll need to use some id that consistent across logged in/logged out states (which could be device id) I think maybe the mistake here is using both IDs. You'll also likely want to make sure that you track those IDs with your metrics as well
s
@agreeable-notebook-26033 @white-fireman-22476 Thank you for you response! Would it be enough to track this random hash within tracking callback event (see pseudo-code below)? In this case I should update the default experiment assignment query, right? If I am correct, which part of assignment query should I update? I would really appreciate you help, thanks in advance!
Copy code
window.gtag("event", "experiment_viewed", {
  event_category: "experiment",
  experiment_id: experiment.key,
  variation_id: result.variationId,
  growthbook_user_id: RANDOM_HASH,
})
w
I am not positive in exactly how that data is saved within GA4 database, but I would imagine that you would need to change the first line and last line to
SELECT growthbook_user_id, ... FROM ... WHERE ... AND growthbook_user_id is not null
How would you be keeping that growthbook_user_id consistent between logged in and logged out users though?
s
I am going to save it in cookie
w
Usually I believe GA4 uses the user_pseudo_id for logged out users.
ok ... then it will be device specific if you are ok with that.
s
But, is there a way to use database user Ids, but keep same variation when user is logged out on same device?
w
Not within growthbook yet. We don't have this for performance reasons.
s
Okay, then we should think on it and decide which solution is best for us. Thank you!
w
Sure thing. Your approach above should work, but the
user_pseudo_id
is I believe pretty much doing the same thing.
s
Is this
user_pseudo_id
stored in
_ga
cookie?
I wonder if it would be better to save ourselves database userId (which is passed to ga4 with gtag(‘set’, { user_id: userId }) in cookie
user_pseudo_id
and use it instead of hash when user is logged out. If user is logged out and cookie doesn’t exist then we can generate random hash
@white-fireman-22476
I mean, I should somehow extract this
user_pseudo_id
from ga and pass to Growthbook attributes otherwise
w
All events that are generated for a user (with a User ID or not) will include a "user pseudo ID" (sometimes this is displayed as the "Device ID" or "App-Instance ID" in reports). On the web, this is supplied by a first-party cookie, and was known as the "client ID" in previous versions of Google Analytics. For Android and iOS apps, this is set to the App-Instance ID.
If it is a test that changes the experience for online logged in users, then use user_id, because then it will be consistent across devices. If it changes the experience also for logged out users, the use the user_pseudo_id - which I think might be referred to anonymous_id in the default GA4 growthbook setup. That way users experiences won't change when they log in.
Your idea of storing the last logged in user_id and keeping that around could work to keep the experience consistent when a user logs out ... but it wouldn't solve the case of a user coming to the site for the first time on a device and logging in.
👍 1
s
@white-fireman-22476 I just found that I can choose
deviceId
attribute to decide which variation should be assigned. So I can safely use
user_id
for logged in users as
id
attribute in growthbook instance. But here comes the question - should I set it to
null
/
'guest'
when user is logged out? And should it be always exactly same as
userId
custom dimension set in GA4?
Or maybe I should use random hash like I do it for
deviceId
? Can I use
deviceId
itself as
id
attribute when user is logged out?
w
Hi. I must say I'm a bit confused. Are the default experiment assignment types when you set up GA4 is not working for you?