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

plain-lizard-13513

11/12/2021, 1:29 PM
hey guys i have a question around logged in/logged out users
Copy code
# segment_user_key => anonymous_id/user_id
  # segment_user_id => anonid/current_user.id
  #
  def analytics_event_tracking
    Analytics.track(
      event: 'Experiment Viewed',
      segment_user_key => segment_user_id,
      properties: {
        experiment_id: experiment.id,
        variation_id: experiment.variation
      }
    )
  end
we were using this code in the backend to fire the experiment viewed event. My comment above shows what those values can be of course - what happens here though is we are potentially losing the context between logged in and logged out users. If somebody comes to the site, triggers an Experiment Viewed event while logged out, registers - then their user key/id will change (now its the logged in version) and so the goal when triggered will be presumably not be measured as it can't be matched? If we instead always use their logged out key - we lose the ability to track them across devices? That said, while looking at the docs https://docs.growthbook.io/lib/ruby#tracking I see that you recommend not sending user identifiers at all. Is that because if we kick this to Segment they'll just handle all of this? Send the logged in/logged out ID's and the query on your side looks for both? Be good to understand this a little more to make sure our implementation is bullet proof
f

future-teacher-7046

11/12/2021, 1:38 PM
Like you said, there's a tradeoff. If you always use logged out key, you lose cross-device tracking, but the user will never switch variations while they are on a single device. If you always use logged in id, then you can track across devices, but anonymous users won't be included in experiments at all. If you do a mashup then users will switch variations when they login. There's no great solution and it depends on the specific experiment. I tend to avoid doing mashups where the id could be either logged-in id or anonymous key. If the experiment is going to include a lot of logged out users, then I use an anonymous key. Otherwise, I use a logged-in id (which excludes anonymous users from the experiment completely).
So what that means in the SDK is that anonId is always set to the anonymous device id. And user_id is either null or the logged-in id.
And then on a per-experiment basis you decide if you want to use user_id (the default) or anonId for assigning variations
Some experiment are obvious (e.g. testing the login flow should be using anonId, testing the account info page should be using userId). For the less obvious experiments, you need to decide if cross-device tracking is more important or if including logged-out users in the sample is more important.
p

plain-lizard-13513

11/15/2021, 5:08 PM
sorry! I didn't say thank you... so thank you! was very much knee deep in a refactor of all of this code
hey @future-teacher-7046 so i've just realised its more complicated than I initially thought? First we have to select whether to use the
user_id
or
anonymous_id
to put them in the experiment... but presumably we have to then make sure we fire the goal using that same ID? Or are you guys able to check the Mixpanel profile of the user and check the ID's? I'm trying to avoid needing to put a second event "Completed experiment goal XYZ" with the specific anonymous_id/user id
f

future-teacher-7046

11/16/2021, 1:05 PM
Mixpanel events track both anonymous and logged in ids for events. On the analysis side you choose which event property you want to use for grouping.
p

plain-lizard-13513

11/16/2021, 1:48 PM
yep - worked it out. Apologies, someone changed something our end that slipped through. We'd stopped connecting anon ids <> user id's
22 Views