How do folks typically handle Segment setting `ajs...
# ask-questions
f
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
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
Fantastic, will give this a go. Thanks Graham!