Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Cached user is not triggering "onEnrolment" #4

Open
thiagonzalez opened this issue Jul 19, 2018 · 0 comments
Open

Cached user is not triggering "onEnrolment" #4

thiagonzalez opened this issue Jul 19, 2018 · 0 comments

Comments

@thiagonzalez
Copy link

thiagonzalez commented Jul 19, 2018

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? :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant