Hello, I am wondering is there a way to check if f...
# announcements
a
Hello, I am wondering is there a way to check if feature is on for user without enrolling him into the experiment. I thought
useFeatureIsOn
does that but from what I can see it just calls evalFeature under the hood which per docs calls tracking. Our use case is that we have specific conditions on when user needs to be enrolled in the experiment so we can't enroll him just to check if feature is on. For example we have 3 CTAs which change based on the experiment. All of those need to check if feature is on but only one of them should actually trigger enrollment.
b
Hey, Ante - what sort of conditions will need to be checked. When building an experiment rule, you can add targeting conditions so you can limit who is included in an experiment. E.G. You can pass in attributes for country, and you can add targeting conditions to so only users in certain countries are included in the experiment. From there, you can have the 3 CTA variations in the experiment.
a
It's not a matter of variations. It's just a matter checking if feature is enabled without enabling it. Code example (it might be easier to grasp)
Copy code
const isFeatureEnabled = useIsFeatureEnabled('feature')

{isFeatureEnabled && <ButtonA />}
{isFeatureEnabled && <ButtonB />}
<ButtonC onClick={() => {
    growthbook.feature('feature')
} />
In the above feature will be enabled as soon as
useIsFeatureEnabled
is called. We want it to get enabled only on
ButtonC
click.
b
So, if I'm understanding correctly, you only want someone to enter the experiment when they click
<ButtonC />
. But, for the conditional rendering, you need to know if they're in the experiment to know whether to show the buttons. Is that correct?
To answer your original question - no, there isn't a way to see if the user is in an experiment without bucketing them into it that I'm aware of. You can add targeting conditions, so, for example, if you had a user attribute of
hasClickedButtonC
, the user would only be bucketed into the experiment (and thus, fire the tracking callback) if that was true. If it wasn't,
useIsFeatureEnabled
would just return false without firing the tracking callBack.
One thing that might be helpful, you the Javascript SDK does have a handy
setAttributes
method - so onClick, you can update the user's attributes. But, you'll want to make sure that the attributes can persist so the next time they land on this page or any others, they have the necessary attributes, otherwise, they might get different variations on subsequent visits.