Hello growthbook team, I am trying to setup stick...
# ask-questions
a
Hello growthbook team, I am trying to setup sticky bucketing in an experiment in an e-commerce based website. I already created an experiment with 3 cohorts and 1 control with user_id as primary hash attribute and anonymous visitor_id as fallback attribute. Initially my users will be in non loggedin state when they first land on the website. So I assign a random visitor_id as fallback attribute and they get assigned a cohort C1. Once they login, their user_id gets available, so I set that in the attributes using setAttributes({...growthbook.getAttributes(), user_id: user id}). Still user is seeing cohort C1 which is expected. However, once this same user lands on the website on different browser, he gets assigned separate visitor_id and different cohort C2. However, once they login, expectation is for them to revert back to C1 cohort as they had same user_id. I also tried setting user_id manually for debugging with new visitor_id while init growthbook sdk in different browser. It still was assigning random cohort on each new browser/new incognito tab
Guys, any help here is appreciated 👍
Is anyone online/available on this channel???
@strong-mouse-55694 can you please help me in this??? Been stuck with this from a week and unable to find any resources. Is there any custom code needed to have bucket stick across devices given different anonid but same user_id (user is first in non loggedin state and later logins with same user_id)
s
What's your end goal for using sticky bucketing? Which implementation of sticky bucketing are you using? https://docs.growthbook.io/lib/js#sticky-bucketing
a
End goal: once new user logins say on browser B1, the cohort assigned on visitor_id (our anonid), should 'stick' with the user_id. When this new user opens the web app on different browser, say B2, and after order placement, they login, they should get assigned the original cohort assigned on B1. Currently Happening: when the new user opens web app on different browser B2, because they are initially non-loggedin, a random cohort based on new visitor_id on B2 gets assigned. This random cohort still stays when user logins. Expected was it would get the same cohort from B1 once they logged in as mentioned in the doc. I am using BrowserCookieStickyBucketService
s
What are you using on the backend for stickybucketing?
a
We aren't using any backend for sticky bucketing. Growthbook initialization and experiment getFeatureValue, everything happens on the frontend. Trying to understand here, would I need to write a custom backend code for persisting user cohort across browsers? Will I need to save the cohort assigned on visitor_id to user_id on the backend and then fetch it later manually? I assumed it came out of the box with growthbook
Hey @strong-mouse-55694 , do let know about above. Thank you in advance :)
s
Hi @acoustic-actor-75733, yes, for cross-browser support, you need some way to persist the identification. See this example for more details: https://docs.growthbook.io/app/sticky-bucketing#front-end-and-back-end-nodejs
a
@strong-mouse-55694 thanks....but there seems to be a bug with ExpressCookieStickyBucketService obj. On express server, I initialized growthbook instance and called getFeatureValue for a sticky bucket service with primary attribute user_id and fallback visitor_id. Let's say cohort assigned is C1. On server user is not logged in. When cookie is transported back to browser and saved in the browser, it seems like double encodeUriComponent is happening. When on browser, user logins later and getFeatureValue is called again after calling setAttribute with user_id, getFeatureValue returns a different cohort C2 always. Expectation: even after login and passing user_id to setAttribute function, cohort should still remain C1. Do let know if it's a bug or intended behaviour? I think it's a bug because when I intercept the Set-Cookie header set by growthbook and call decodeUriComponent once before passing the updated Set-Cookie header, it transports cookie back in correct format in browser. Also this time when user logins and I re-call getFeatureValue, it returns the original C1 cohort!
Also, any chance could you point me to a demo codebase of persisting cross browser sticky bucketing?