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

Feature request: Being able to skip initialization of Piwik #41

Closed swergas closed 6 years ago

swergas commented 7 years ago

Hi

Our web app assembl adds dynamically a piwik tracking script to the DOM of its pages, if an administrator has activated piwik tracking and has provided a piwik site id in the administration panel.

So, as we are progressively migrating our application to React, we would like to use piwik-react-router to track user navigation in React routes, but using an already initialized Piwik tracking script.

I think this solution is better than a solution where we would try to get our piwik configuration data from our application server and then use this data to initialize piwik-react-router.

And I see no other solution than these 2 for now.

Do you have any ideas about this type of use case? I will provide a pull request with the changes we made to skip piwik initialization.

Edit: I provided a PR here: https://github.com/joernroeder/piwik-react-router/pull/42

joernroeder commented 7 years ago

Hey @swergas, thanks for opening the issue and submitting the pull request!

Currently i see the following use cases:

the second case could be done by:

  1. inject and instantiate piwik from the outside (your case again) and setting the appropriate options in piwik-react-router
  2. dynamically test if a piwik instance already exists and create or use it depending on the result of the test. An option/flag like injectScript or alreadyInitialized should therefore test if a) the piwik.js script is present and b) inspecting the window._paq object to test if it's a valid piwik instance or not.

Of couse we have to deal with async initialization of piwik itself but by doing the test fully dynamically instead of setting boolean options my second use-case wouldn't depend on a pre-instantiated piwik instance and component tree which is initialized at first could set up piwik as well.

This are just some ideas i had when i saw your fork and the changes you made. what do you think?

joernroeder commented 6 years ago

closing this in favor of #46