guillaumeparis2000 / react-piwik

Library that allow to connect piwik with the react-router and track custom events
31 stars 17 forks source link

push of undefined #1

Closed sephi-dev closed 7 years ago

sephi-dev commented 7 years ago

Hi guys,

just a little bug, I don't know if I do the thing the good way but here is the point :

heres is the code :

import ReactPiwik from 'react-piwik';

class PiwikEvents {
  constructor(opts) {
    ReactPiwik.push(['enableHeartBeatTimer']);
  };

  setCustomDimension(opts) {
    ReactPiwik.push(['setCustomDimension', customDimension = opts.nb, customDimensionValue = opts.dimensionValue]);
  };

  addTrackEvent(opts) {
    ReactPiwik.push(['trackEvent', opts.page, opts.action]);
  };

  setUserId(opts) {
    ReactPiwik.push(['setUserId', opts.user]);
  };

};

const p = new PiwikEvents();

export function setUser(opts) {
  p.setUserId(opts);
};

export function setNewDimension(opts) {
  p.setCustomDimension(opts);
};

export function setTrackEvent(opts) {
  p.addTrackEvent(opts)
};

But when my app is running, in my console I have : Uncaught TypeError: Cannot read property 'push' of undefined

Any idea ?

guillaumeparis2000 commented 7 years ago

Hi,

It seems that your PiwikEvents constructor is run before creating and connecting the react-piwik to the history.

sephi-dev commented 7 years ago

Yep, found it too late ahaha sorry about that mate.