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

Using defaultVariantName for same experiment in multiple places breaks experiment #13

Closed Amber-Williams closed 3 years ago

Amber-Williams commented 4 years ago

I have the following with a defaultVariantName defined in one component with the same experiment as another component. My app works with just one defined but if I want to define it again to make it consistent it breaks.

// component 1
<Experiment name="x" defaultVariantName="A">
  <Variant name="A" >
    <AIntro/>
  </Variant>
  <Variant name="B">
    <Intro/>
  </Variant>
</Experiment>

// component 2
<Experiment name="x">
  <Variant name="A">
    <AHeader/>
  </Variant>
  <Variant name="B">
     <Header/>
  </Variant>
</Experiment>

A suggestion is to define the defaultVariantName within the .defineVarients() method so it is defined where the other definitions are created PushtellEventEmitter.prototype.defineVariants = function(experimentName, variantNames, variantWeights, defaultVariantName)

moretti commented 4 years ago

Hi @Amber-Williams, so in this case you're rendering two experiments with same name and you would expect component 2 to choose variant A on SSR, because you passed defaultVariantName to component 1? Does component 2 render after component 1? Have you tried calling emitter.setActiveVariant instead?

Can you create a small example on codesandbox.io to illustrate the problem? Thanks!