most-plumber-30247
08/24/2023, 10:42 AMdisplay-fees-v2
with the default value showPriceFeesWithInfo
I added a forced rule that says : if totalFees
0 then serve showNoFees
(see screenshot)
In my code I added the following :
const displayFees = useFeatureIsOn('display-fees-v2');
const { value } = useExperiment({
key: 'display-fees-v2',
variations: ['showPriceFeesWithInfo', 'showFeesWithInfo', 'showFeesWithoutInfo', 'showNoFees'],
});
const showPriceFeesWithInfo = value === 'showPriceFeesWithInfo';
const showFeesWithInfo = value === 'showPriceFeesWithInfo';
const showFeesWithoutInfo = value === 'showPriceFeesWithInfo';
const showNoFees = value === 'showPriceFeesWithInfo';
const growthbook = useGrowthBook();
useEffect(() => {
if (!growthbook) return;
const attributes = growthbook.getAttributes();
growthbook.setAttributes({
...attributes,
totalFees: totalFees,
});
growthbook.refreshFeatures();
}, [totalFees, growthbook]);
Once I go to my page I see the default variation showPriceFeesWithInfo
while I want it to be showNoFees
• How do I force showNoFees when my totalFees are zero ?
Thanks!happy-autumn-40938
08/24/2023, 7:22 PMuseExperiment()
hook actually is a bypass hook for just running an inline experiment independent of any associated feature flags. Since your override rules and experiment rules are in your feature flag, you should be able to just evaluate the feature flag directly without referencing the experiment in your code.most-plumber-30247
08/25/2023, 8:46 AMuseFeature
instead of useExperiment
as follow:
const growthbook = useGrowthBook();
const { value } = useFeature('display-fees-v2');
const showPriceFeesWithInfo = value === 'showPriceFeesWithInfo';
const showFeesWithInfo = value === 'showFeesWithInfo';
const showFeesWithoutInfo = value === 'showFeesWithoutInfo';
const showNoFees = value === 'showNoFees';
useEffect(() => {
if (!growthbook) return;
growthbook.setAttributes({
...growthbook.getAttributes(),
totalFees: totalFees,
});
growthbook.refreshFeatures();
}, [totalFees, growthbook]);
However, if totalFees: 0
I still get the showPriceFeesWithInfo
instead of showNoFees
And now I see no experiments at all. Is this normal?
Do you know what am I doing wrong ?happy-autumn-40938
08/25/2023, 6:04 PM<GrowthBookProvider growthbook={gb}>
component? If so, maybe try console logging inside your useEffect hook (before and after the return
) to see whether that's even firing / updating the user attributes.most-plumber-30247
09/11/2023, 9:23 AM<GrowthBookProvider growthbook={gb}>
, I logged growthbook in the useEffect and I see my user attributes ebing updated right away, but I still get an empty array for experiments...
I guess I will have to use useExperiment
and implement an if else in my code to get the correct experiment, but it's a shame I don't get what I am doing wrong.