marvelapp / react-ab-test

A/B testing React components and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for Mixpanel and Segment.com.
MIT License
240 stars 47 forks source link

Working with NextJS #12

Closed YoannDelpierre closed 4 years ago

YoannDelpierre commented 4 years ago

Hey,

I'm looking how to I can use this wonderfull package with NextJS and especially with SSR.

I'm using userIdentifier like you said, but if I force the local value to A test, it renders B test and update the local value to B value instead of keeping A value.

Any idea how I can manage this ?

Thanks

moretti commented 4 years ago

Hi @YoannDelpierre, did you find a solution to this problem?

YoannDelpierre commented 4 years ago

Hi @moretti , yes it's ok. I misunderstood how it works form react-ab-test point of view.

It's totally cool right now.

Thanks

lpanjwani commented 3 years ago

@YoannDelpierre Could you share how you overcame this issue?

joselevelsup commented 3 years ago

@YoannDelpierre Yeah, can you please share how you solved this issue? I am having the same issue using userIdentifier. Thanks!

YoannDelpierre commented 3 years ago

@joselevelsup @lpanjwani Nothing special, I just put the userIdentifier as props in Experiment component

<Experiment name={EXPERIMENT_RANGE_NAME} userIdentifier={userId}>
<Variant name={EXPERIMENT_RANGE_VARIATIONS.WITH}>xxx</VARIANT>
<Variant name={EXPERIMENT_RANGE_VARIATIONS.WITHOUT}>yyy</VARIANT>
</Experiment>

And I used

useEffect(() => {
    emitter.defineVariants(EXPERIMENT_RANGE_NAME, [
      EXPERIMENT_RANGE_VARIATIONS.WITH,
      EXPERIMENT_RANGE_VARIATIONS.WITHOUT
    ]);
    emitter.calculateActiveVariant(EXPERIMENT_RANGE_NAME);
}, [])