Hi, searching for suggestion here. The case is whe...
# ask-questions
h
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
Is this for testing/QA purposes or something you actually want to do in production?
h
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
And which SDK language are you using?
h
js
React
f
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
👍
will the forcedFeatures cover the setFeatures about the same key?
f
Yes, the feature keys need to match for the overrides to work
l
So it doesn’t matter if we set one feature twice, both in features and forced features
f
Correct. The forced value will take precedence if both are set
🙌 1
l
Thank you, this solve my problem.