react-ab-experiment icon indicating copy to clipboard operation
react-ab-experiment copied to clipboard

Cached user is not triggering "onEnrolment"

Open thiagonzalez opened this issue 7 years ago • 0 comments

Hello guys, I'm implemeting a/b test here with react-ab-experiment and Google Optimize. The first access from user calls onEnrolment, which sends all ga events to Google, but when the cache is created, onEnrolment doesn't trigger again and I don't send the ga events to Google.

Here is an example of what I'm applying to the project:

import React from 'react';
import {Experiment, Variant} from 'react-ab-experiment';

const experimentID = 'xxx';

function handleEnrolment(experimentId, variantName) {
  console.log(experimentId, variantName);

  ga('create', 'xxx-x');
  ga('set', 'expId', experimentId);
  ga('set', 'expVar', variantName);
  ga('send', 'pageview');
}

const LocalStorageCache = {
  get: (key) => window.localStorage.getItem(key),
  set: (key, value) => window.localStorage.setItem(key, value)
}

const Example = () => (
  <div>
    <Experiment id={experimentID} onEnrolment={handleEnrolment} cache={LocalStorageCache}>
      <Variant name={0}>testing 0</Variant>
      <Variant name={1}>testing 1</Variant>
    </Experiment>
  </div>
);

Cache is getting the right information (0 or 1), but I need to always send to GA all the events inside handleEnrolment. Could you please help me? :)

thiagonzalez avatar Jul 19 '18 18:07 thiagonzalez