guillaumeparis2000 / react-piwik

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

Matomo support? #22

Closed kristian2x closed 4 years ago

kristian2x commented 4 years ago

Does this support matomo and react-router v4?

guillaumeparis2000 commented 4 years ago

It support matomo but for react-router v4 I haven't try it for the moment with this plugin. Can you try it and give me feed back about it?

kristian2x commented 4 years ago

thanks, which react-router is officially supported then? I'll test v4 and report back.

Findus23 commented 4 years ago

Hi @guillaumeparis2000,

Could you report back if this library works with the latest Matomo and React(router) version?

If so, we could add it to the https://matomo.org/integrate/ page.

See also https://github.com/joernroeder/piwik-react-router/issues/60

cc @mattab

guillaumeparis2000 commented 4 years ago

Hi @Findus23,

This library work with the latest Matomo but I haven't tested it with the last react router version. For the moment I haven't got any time to do this test, if you can test it and report the result in this issue?

Thanks

Findus23 commented 4 years ago

Unfortunatly I know hardly anything about React, but maybe @idodav can confirm this.

havsar commented 4 years ago

For me it doesn't work with react-router@v5:

TypeError: Cannot read property 'path' of undefined
t.value
node_modules/react-piwik/lib/React-Piwik.js:88
  85 | value: function (t) {
  86 |   var e = this,
  87 |       i = void 0 === t.getCurrentLocation ? t.location : t.getCurrentLocation();
> 88 |   return this.previousPath = i.path || (i.pathname + i.search).replace(/^\//, ""), this.unlistenFromHistory = t.listen(function (t) {
     | ^  89 |     e.track(t);
  90 |   }), t;
  91 | }
havsar commented 4 years ago

Ok, I got it working:

react-router@v5 Matomo

I had to install the history module from npm (not use the global one).

const piwik = new ReactPiwik({
    url: '//localhost',
    siteId: 1,
    trackErrors: true,
    jsFilename: 'matomo.js',
    phpFilename: 'matomo.php'
})

piwik.connectToHistory(createHashHistory())
guillaumeparis2000 commented 4 years ago

Allready fixed