-
Notifications
You must be signed in to change notification settings - Fork 21
implemented dynamic already-initialized function to be able to use multiple piwik-react-router instances on the same page #46
Conversation
|
Is this PR going to get merged? |
|
@larsnystrom yes! I've worked on this today. Initial issue is #41 and pull request is #42. |
|
I just started using piwik-react-router today, so this is what I though of: (not everything is related to this PR, sorry about that)
But overall I'm happy about how things worked out. Thank you for this package! |
|
My god, I didn't realize until now you created this today! I thought this was some forgotten PR made months ago. Sorry! |
|
@larsnystrom i'll look into this tomorrow. but yes the feature request is a couple of month old but personally a static flag felt to unflexible to me therefore i'm trying to find a better solution. |
|
The solution I would've wanted when I started would've been to automatically find the global piwik instance without me having to add a data- attribute to the script tag, but this is definitely good enough. Thanks again! |
|
You don’t have to provide anything. You’re just able to use a different attribute name... |
|
@larsnystrom as you are adding the piwik script tag on the server side you don't have to mess around with Imagine an other case – and this is what this pull request is trying to fix – where you will instantiate at least two React-Apps/Root-Components on a page, both independent from each other (e.g. a chat and a photogallery) and both try to add its own piwik instance to the page. Now just one of them will make it and the other one will use that instance too. import React from 'react';
import { render } from 'react-dom';
import { Router } from 'react-router-dom';
import createHistory from 'history/createBrowserHistory';
import PiwikReactRouter from 'piwik-react-router';
import App from 'containers/App';
const piwik = PiwikReactRouter({
enableLinkTracking: false, // as the piwik instance is shared you don't have to disable it here. it's just resetting true to true otherwise.
ignoreInitialVisit: true,
trackErrors: true,
updateDocumentTitle: false,
injectScript: false
});
const history = createHistory();
render(
<Router history={piwik.connectToHistory(history)}>
<App />
</Router>,
document.getElementById('app')
); |
|
@larsnystrom const piwik = PiwikReactRouter({
trackErrors: true,
updateDocumentTitle: false,
injectScript: false
});<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
// remove it here _paq.push(['trackPageView']);
// remove it here _paq.push(['enableLinkTracking']);
(function() {
var u="//{$PIWIK_URL}/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', {$IDSITE}]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code --> |
|
Yes, I tried |
|
@larsnystrom hmmm…… Could you try and remove Could you also add a |
|
I think that's a brilliant idea. If I remove the 'setSiteId' from the server-side code, what happens is the Piwik server returns 400 (Bad request) when the first action is sent, because the
Without |
|
@larsnystrom perfect – that is exactly what i was looking for! I'll add some tests with your |
|
|
|
ok, i'll have a look, it should be documented somewhere in the official piwik documentation. |
…d or url if injectScript is disabled #46
|
@larsnystrom i've updated the library and added additional tests but i had to push the variables to |
|
I think I'm pretty close to the default piwik installation. |
|
@larsnystrom thanks for looking into this up again. I also looked in piwiks tracker script and found this jslint comment which sets |
# Conflicts: # index.js
index.js
Outdated
| _isShim: false, | ||
| track: track, | ||
| push: push, | ||
| setUserId, setUserId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be setUserId: setUserId (colon, not comma)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, how could that pass the tests 🤔
|
@larsnystrom i have to be afk tomorrow therefore i can't publish a new version to npm right now but feel free to use |
|
I can't get 0.12.0 to work as expected. I'm getting the |
|
hm, i think we run into the
|
|
No, I'm still getting the same message when I change all refernces to When I fixed that (by adding the correct |
|
i've digged a bit more into piwiks current implementation and i think i've found a solution. check out my latest changes --> https://github.com/joernroeder/piwik-react-router/blob/master/index.js#L59 |
|
Yes, that seems to do the trick! The last thing I would like to suggest is to replace the check for a script tag with a check if I think a check for typeof window !== 'undefined' &&
typeof window._paq !== 'undefined' &&
typeof window._paq.push === 'function'should be all we need. The Thank you for all your work! |
|
@larsnystrom yes that sounds like a much simpler solution to detect piwiks existence. Testing the existence of |
|
@larsnystrom i've updated the master branch! could please check it out, i'll push it to npm afterwards… |
|
That works! |
|
perfect! i've just published the new version |
|
Thank you! 👏 |
No description provided.