Date of slack thread: 5/8/24
Anonymous: Hello! Been testing Statsig with the React StatsigProvider for a future A/B testing feature, and I have 2 questions regarding uninitialized events:
<StatsigProvider
sdkKey={statsigKey}
waitForInitialization={true}
user={abTestingUser}
>
{renderContent()}
</StatsigProvider>
And what is happening is that I get 1 uninitialized event for every view event in the experiment. Why is that? I thought using waitForInitialization={true}
is meant to solve this case.
Vijaye (Statsig): The bot is right. I’m including some SDK team members to help with #1. Could you post code snippets on how you are getting experiment variants?
Anonymous: Yea well the experiment variants are pretty straightforward. Inside a component rendered in the scope of the provider, I do:
const { config: zeroStateExperiment, isLoading: isExperimentLoading } = useExperiment(AbTestingExperiments.BalanceZeroStateVariations, false);
const zeroStateVariant = zeroStateExperiment.get(ZeroStateVariationsParams.BalanceVariant, '');
const zeroStateHtmlUrl = zeroStateExperiment.get(ZeroStateVariationsParams.BalanceHtmlUrl, '');
And regarding the bot answer, how can I do that:
To prevent initializing the SDK unnecessarily, you could conditionally wrap your app with the StatsigProvider only when there are active experiments or feature gates that need to be evaluated. This would require some logic in your app to determine when the SDK should be initialized. If you need further assistance with this, please share the link to the specific gates or experiments, and a Statsig team member will be able to help you further.
I mean, I don’t want to change the code each time I have/don’t have active experiments, ideally I’d like to be able to get it from Statsig and then conditionally render it.
Vijaye (Statsig): That part about initializing the SDK conditionally isn’t right. I don’t know where the bot got that idea from. Your code looks right. Could it be that initialize is timing out? Regardless of the experiment state, you shouldn’t be seeing “uninitialized”.
Anonymous: Locally it doesn’t show any uninitialized events, but when deployed it got the uninitialized event, then immediately the expected event. And then I get this in the experiment.
Tore (Statsig): To your second question: checks to non-active experiments do not count towards metered events for your project: “Experiment checks that result in no allocation (e.g., the experiment hasn’t started, or has finished) or Feature Flags that have been disabled (fully shipped or abandoned with no rule evaluation) do not generate Metered Events.” Pricing
Tore (Statsig): To the first question - is your user object static, or is it changing?