joernroeder / piwik-react-router

Piwik analytics component for react-router
https://www.npmjs.org/package/piwik-react-router
MIT License
61 stars 22 forks source link

Initial visit is not reported (only url changes are reported) #30

Closed mnieber closed 7 years ago

mnieber commented 7 years ago

If I connect piwik and visit my website, nothing is reported to piwik. But when I click internal links on my page, then piwik shows me a new visit and action.

Could it be that piwik-react-router is only listening to changes, and not to the initial route?

mnieber commented 7 years ago

I fixed it by removing connectToHistory and using:

let fireTracking = function() {
  if (window.location) {
    this.piwik.track(window.location);
  }
}.bind(this)

return (
    <Router history={browserHistory} onUpdate={fireTracking}>
    // etc, etc
);
joernroeder commented 7 years ago

Yes, You're totally right! Thanks for reporting and looking into it. I'll figure out a solution at the weekend which will use your solution as the default inside connectToHistory and a configuration option to disable it again.

joernroeder commented 7 years ago

I think i'll use history.location to be consistent with the first attribute of the piwikReactRouter.track function.