https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
f

faint-portugal-8257

04/14/2022, 1:44 PM
How do folks typically handle Segment setting
ajs_anaonymous_id
and the growthbook id attribute in the growthbook react SDK? We're loading both libraries as part of our NextJS app, and there appears to be a race condition in the segment sdk and growthbook initializing for first time visitors. It takes some time for the anonymous id to be generated, so we've been manually generating one at the time of the Growthbook initialization to make sure it's set, and then setting the anonymous id manually for analytics.js as well.
f

fresh-football-47124

04/14/2022, 3:52 PM
I suggest using the ready event to update the attributes within GrowthBook. https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#ready
something like:
Copy code
analytics.ready(function() {
  growthbook.setAttributes({
    ...growthbook.getAttributes(),
    id: analytics.user().anonymousId();
  });
});
f

faint-portugal-8257

04/15/2022, 11:47 AM
Fantastic, will give this a go. Thanks Graham!
9 Views