I am struggling with specifying the required ID at...
# announcements
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
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
@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,
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?
I am going to save it in cookie
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.
But, is there a way to use database user Ids, but keep same variation when user is logged out on same device?
Not within growthbook yet. We don't have this for performance reasons.
Okay, then we should think on it and decide which solution is best for us. Thank you!
Sure thing. Your approach above should work, but the
is I believe pretty much doing the same thing.
Is this
stored in
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
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
I mean, I should somehow extract this
from ga and pass to Growthbook attributes otherwise
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
@white-fireman-22476 I just found that I can choose
attribute to decide which variation should be assigned. So I can safely use
for logged in users as
attribute in growthbook instance. But here comes the question - should I set it to
when user is logged out? And should it be always exactly same as
custom dimension set in GA4?
Or maybe I should use random hash like I do it for
? Can I use
itself as
attribute when user is logged out?
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?