https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
h

helpful-carpenter-3208

04/25/2022, 2:45 PM
Hi, searching for suggestion here. The case is when we want to use url parameter to control the feature flag. like
/signup?feature-a=true
is there a best practice for growthbook to support it? I know we can define a force rule and inject url parameter to setUser. but it seems not the best way to do it.
f

future-teacher-7046

04/25/2022, 2:47 PM
Is this for testing/QA purposes or something you actually want to do in production?
h

helpful-carpenter-3208

04/25/2022, 2:49 PM
I think for both. but testing should be the main issue here. we don’t want to add too many rules only for testing.
for production. the use case might be we want to some signup page opened from a special source to have these special features.
f

future-teacher-7046

04/25/2022, 2:51 PM
And which SDK language are you using?
h

helpful-carpenter-3208

04/25/2022, 2:52 PM
js
React
f

future-teacher-7046

04/25/2022, 3:00 PM
You could use the
setForcedFeatures
method to force specific values based on the query string. It would look something like this:
Copy code
// TODO: get from the actual querystring
const querystringKeyValues = [["feature-a", true]]

const forcedFeatures = new Map();
querystringKeyValues.forEach(([key, value]) => {
  forcedFeatures.set(key, value);
});
growthbook.setForcedFeatures(forcedFeatures);
👍 1
l

lively-belgium-36533

04/25/2022, 3:03 PM
👍
will the forcedFeatures cover the setFeatures about the same key?
f

future-teacher-7046

04/25/2022, 3:26 PM
Yes, the feature keys need to match for the overrides to work
l

lively-belgium-36533

04/25/2022, 3:28 PM
So it doesn’t matter if we set one feature twice, both in features and forced features
f

future-teacher-7046

04/25/2022, 3:29 PM
Correct. The forced value will take precedence if both are set
🙌 1
l

lively-belgium-36533

04/25/2022, 3:31 PM
Thank you, this solve my problem.
13 Views