Hi there, Just discovered Growth and I think it's...
# contributing
i
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.)
fetch("<https://s3.amazonaws.com/myBucket/features.json>")
  .then((res) => res.json())
  .then((parsed) => {
    growthbook.setFeatures(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
growthbook.setAttributes()
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
setAttribute
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.
f
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.
i
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?
f
We recommend passing two identifiers into GrowthBook attributes.
id
for logged in user id (set to empty string for anonymous) and
anonId
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.
i
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 ?
f
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.
i
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?
f
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.
i
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?
f
Are you using the React SDK?
i
Vanilla JS
f
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
setAttributes
with the new account info
i
Amazing. That's exactly what I was hoping for. Super grateful for your help Jeremy.