https://www.growthbook.io/ logo
#announcements
Title
# announcements
f

few-memory-16563

08/08/2022, 10:08 PM
Hi, we're trying to use an override rule to force anyone who goes to a URL containing the word
hold
into the
on
version of a feature. Do we have to include URL as an attribute in the SDK for this to work, or does growthbook read from the current page URL by default (or something else?)
f

future-teacher-7046

08/08/2022, 10:10 PM
Yes, you would need to add the current URL as an attribute in the SDK.
f

few-memory-16563

08/08/2022, 10:11 PM
got it. Thank you!
We have added the attribute but it's not working as I would have expected, any pointers as to where we might be going wrong? • two rules on the feature: first is the force rule and second is an A/B split rule • we are setting the attribute on all pages that have
hold
in the URL • this is how i have the rule syntax • when i test it by visiting one of the
hold
URLs in an incognito window, then going to another page in the site that has the feature as an A/B, I'm not seeing the feature 100% of the time (which is what I'm trying to achieve)
f

future-teacher-7046

08/09/2022, 4:16 PM
So to make sure I understand, when someone visits that URL, you want them to get a specific value for the rest of their browsing session?
f

few-memory-16563

08/09/2022, 4:27 PM
exactly
f

future-teacher-7046

08/09/2022, 4:38 PM
Ok, we don't have a built-in way to do that. You would need to persist that yourself. If this is front-end, you can easily do that with
window.sessionStorage
Then you can force the value directly in the SDK using the setForcedFeatures method. No need to deal with rules or the GrowthBook UI for that.
f

few-memory-16563

08/09/2022, 4:44 PM
ok. And as long as the session is forced into the
on
version of the feature, will the A/B test pick that up as a session? Or will it be ignored? (i am trying to achieve the former)
f

future-teacher-7046

08/09/2022, 4:53 PM
If you use
setForcedFeatures
it will ignore any rules and just immediately assign that value to the user. There is also
setForcedVariations
which will use the A/B test rule and just always force the specified variation.
f

few-memory-16563

08/09/2022, 4:55 PM
ok i see. So in this case it sounds like
setForcedVariations
is actually what we want. Thanks for your help!
Is there any documentation about that method?
f

future-teacher-7046

08/09/2022, 5:19 PM
I don't think there is right now. You pass an object mapping the experiment tracking key to the variation you want to assign.
Copy code
growthbook.setForcedVariations({
  "my-experiment": 0 
  // 0= control, 1= 1st variation
})
👍 1
51 Views