Hello, I am using the `growthbook.setAttributes` m...
# ask-questions
p
Hello, I am using the
growthbook.setAttributes
method in order to implement basic targeting rules. It seems that when I call
setAttributes
for a given user, the set attributes do not persist in the next page view. For example, I have a test that I want to only run in the US. When a user lands on the homepage I call
setAttributes(country_code: 'US')
. The issue I'm seeing however is on the next page (say the user clicked on an article), attributes is now empty again. I was under the impression that these attributes would be saved in cookies or local storage and persist across the user's experience. Is this not the case? What is the recommended way of handling this.
f
Hi Ian, sorry for the delay - you have to call getAttributes() then append on anything else you need - setAttributes() over writes existing ones
GrowthBook does not do any saving of attributes by default
its fairly easy to add code to remember which side of the experiment were exposed to if re-assigning is not practical
👍 1
p
@fresh-football-47124 I think an improvement might to add a feature that lets you tell these attributes to persist across page views.
growthbook.persistAttributes = true
or
growthbook.saveAttributesToCookies()
If you're running an experiment that relies on attributes only available on another page, you have to do this so I would assume it's a pretty common use case.
Sorry I should've put this in #feedback channel. Thanks for your help though!
f
you can also open a github issue for this
p
sure! Will do