New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change default recommended JavaScript Tracking Code #10797
Comments
|
FYI: In #10878 (comment) we also discuss about how to be using Piwik JavaScript Tracker when piwik.js is loaded first and only initialized later. Eg we could initialize Piwik like this: _paq.push(['addTracker', [
['enableLinkTracking'],
['setSiteId', '5'],
['setTrackerUrl', u+'piwik.php'],
['trackPageView']
]]); Ideally, it would have always looked like this as this is clear. We actually define to add a tracker and configure it. If no When receiving an array of configurations we would be able to sort the methods before executing them and it wouldn't matter whether Piwik is already loaded or not. I think this version is even more readable etc and best: I think we could implement it in a way to keep BC although not 100% sure as it is a bit tricky to not ending up with 2 trackers in this case. Any thoughts on this? |
@tsteur the idea is good I think, but not needed for now so maybe you could move the comment to a new issue if you think it's worth it as this issue is already closed |
OK will create new issue. This might be pretty much the only way to make tracker work for people that initialize tracker with paq after piwik was loaded and for people that use multiple trackers and not paq |
I am unable to edit the tracking code generated by Piwik 3.0.3. I need to add 2nd Piwik server configuration |
@waa8288 what exactly are you trying to achieve? You can modify the tracking code however you want before inserting it into your website. |
I can not edit it. I want to edit the tracking code in Piwik and add 2nd Piwik server info so the data from a host can go to 2 Piwik servers. Here is what I want to achieve:
Collect your analytics data into two or more Piwik servers
The example below shows how to use addTracker method to track the same analytics data into a second Piwik server. The main Piwik server is piwik.example.org/piwik.php where the data is stored into website ID 1. The second Piwik server is analytics.example.com/piwik.php where the data is stored into website ID 77.
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//piwik.example.org/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '1']);
// Add this code below within the Piwik JavaScript tracker code
// Important: the tracker url includes the /piwik.php
var secondaryTracker = 'https://analytics.example.com/piwik.php';
var secondaryWebsiteId = 77;
// Also send all of the tracking data to this other Piwik server, in website ID 77
_paq.push(['addTracker', secondaryTracker, secondaryWebsiteId]);
// That's it!
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>
Thank you for the reply.
…________________________________
From: Stefan Giehl <notifications@github.com>
Sent: Wednesday, May 3, 2017 10:27:20 AM
To: piwik/piwik
Cc: Negib Sherif; Mention
Subject: Re: [piwik/piwik] Change default recommended JavaScript Tracking Code (#10797)
@waa8288<https://github.com/waa8288> what exactly are you trying to achieve? You can modify the tracking code however you want before inserting it into your website.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#10797 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFe0LdhTYZfi0yhcYalXowN7xMjCHO59ks5r2I7IgaJpZM4Kiuqt>.
|
@waa8288 You don't need to edit the code in the box piwik shows. That's just an example of the code you need to add into the header of your website. So if you want to modify the tracking code just change it on your website. |
I did that on client hosts side. May be I am missing something. Are you saying that the tracking code in
the Piwik server is just an example not part of Piwik configurations and all the change that I want to do (adding 2nd Piwik server) should be the tracking code copied to client hosts?
…________________________________
From: Lukas Winkler <notifications@github.com>
Sent: Wednesday, May 3, 2017 10:44:11 AM
To: piwik/piwik
Cc: Negib Sherif; Mention
Subject: Re: [piwik/piwik] Change default recommended JavaScript Tracking Code (#10797)
@waa8288<https://github.com/waa8288> You don't need to edit the code in the box piwik shows. That's just an example of the code you need to add into the header of your website.
So if you want to modify the tracking code just change it on your website.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#10797 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFe0LaefLyWjk4R8gWcyuqtHTT4DrPZmks5r2JK7gaJpZM4Kiuqt>.
|
The tracking code shown in Piwik should be copied into your website. For more information about tracking multiple Piwiks check out https://piwik.org/blog/2017/02/complete-guide-tracking-websites-web-apps-multiple-piwiks-easily-efficiently/ |
Our default tracking code that we generate in Piwik and show on websites looks like this:
There are a couple of problems with this:
rec=1
would need to be added to make it actually worktrackPageView
see https://github.com/piwik/plugin-CustomDimensions/issues/23 . I ran into this issue myself recently and took me a while to figure out why set custom variables were not tracked.As it is not good to discuss about different topics / problems in one issue I want to focus on point "2) Positioning of trackPageView" .
To solve this there are many options:
a) We could just add a comment to the tracking code showing them where to add calls like
setCustomVariable
.b) Move
trackPageView
further downc) We could automatically execute an initially set custom variable and custom dimension before
trackPageView
but this may not be wanted under circumstances and doesn't fix the problem in general for other tracking methods etc.d) I'm sure there are some more ideas
We should ideally not change anything here in Piwik 2. I know some users perform replacements on a fetched / generated tracking code such as the WordPress Piwik Plugin (
str_replace('...trackPageview...', '...', $trackingCode)
). To make sure to not break anything there it would be better to only change it in Piwik 3.I also wanted to embed the JS file via
<script async defer src="piwik.js"></script>
as it is better readable etc but then users need to specify the domain twice which is no good.The text was updated successfully, but these errors were encountered: