Hi, we're trying to use an override rule to force ...
# announcements
f
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
Yes, you would need to add the current URL as an attribute in the SDK.
f
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
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
exactly
f
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
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
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
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
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
168 Views