Hi there, Just discovered Growth and I think it's...
# contributing
Hi there, Just discovered Growth and I think it's great and I'm excited to start using it. I'm trying to implement it and I've run into a few snags. Any help would be much appreciated. Our App is freemium so people can use the core feature without needing to signup. This means that we don't always have user details when people use the app. I'm calling the Growthbook context as the app loads and fetching features as instructed in the docs here: https://docs.growthbook.io/lib/js
Copy code
// Create a GrowthBook context
const growthbook = new GrowthBook();

// Load feature definitions (from API, database, etc.)
  .then((res) => res.json())
  .then((parsed) => {
My questions are: 1. How does Growthbook know which feature to assign without knowing who the user is at this point? 2. If the user then creates an account and we use use
to update the id, will whatever anonymous tracking token that was used previously be merged into the new ID we give it when the user signups? 3. Our app also allows people to create multiple accounts and switch between them. If this happens do we have to refresh the data? I'm assuming
won't work here as we want to switch to an existing user id not update the existing user with a new ID. Any guidance or direction on how to think about and manage this would be much appreciated.
Hi Josh. In order to run an experiment or do a rollout with a feature, GrowthBook needs some sort of user identifier in the attributes. If it's an anonymous visitor, you can use something like a session cookie or a distinct id stored in local storage.
When adding a rollout or experiment to a feature, it will prompt for what attribute you want to use to split users.
Thanks Jeremy. Got it, so either we don't instantiate Growthbook till we have access to a user identifier or we use a generate a session cookie.
If this is how a session starts, and then a users signups during the session, will updating the ID merge the old cookie with the new permanent id?
We recommend passing two identifiers into GrowthBook attributes.
for logged in user id (set to empty string for anonymous) and
with a cookie id or similar that is passed for all users, logged in and anonymous.
When you track events into your data warehouse or analytics system, also pass both of those IDs. Then GrowthBook can merge them when doing the analysis.
Great so you are saying that Growthbook does merge permanent and anon IDs. Does it give priority to the permanent Id on repeat visits? For example, someone starts with anonId and then adds a permanent ID later in the session when they create their account. When the user comes back to the app the next time and we initialise them with the permanent ID will they still be placed into anon ID bucket they started with the first time ?
When you create an experiment, you specify what attribute you want to use for bucketing. So if you choose an anonymous id, it will always use that to assign a variation, whether or not the person is logged in.
The merging happens when we analyze results. We can join an anonymous id to a logged in id if needed when calculating metrics.
So what is the rationale for passing in a anonymous ID and a permanent ID when instantiating context if they cannot be merged and experiments will only ever use one of them?
Some experiments may only be on the logged in portion of your app. In that case you could use a userId for assignment. That way if the person logs in on another device, they will keep seeing the same variation. Other times you want to test something that includes logged out users so you would use an anonymous id. The assignment part for an experiment will only use one of the IDs. But when analyzing results, we can map between the IDs when needed. For example if the person sees an experiment, then logs in and completes an action, we can tie those together.
Got it. I think I understand. I may have follow-up questions once I've digested this. But this is ridiculously helpful. Thank you so much.
One last question about switching between accounts. Our app lets people switch between workspaces. Is there a way to refresh the context when this happens? How do you recommend context switching in an app?
Are you using the React SDK?
Vanilla JS
So there's a hook in the GrowthBook instance to set a render function that is called anytime attributes or features change. You can use that to re-render your application and re-evaluate all of the features.
Copy code
growthbook.setRenderer(() => {
  // re-render your app here
Then when the user switches accounts, you would just call
with the new account info
Amazing. That's exactly what I was hoping for. Super grateful for your help Jeremy.