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
improving JavaScript tracking code performance #9077
Comments
I did this as well to make http://developer.piwik.org faster: var _paq = _paq || [];
_paq.push(["setCookieDomain", "*.piwik.org"]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
function track() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://demo.piwik.org/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "siteid"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
}
if (window.addEventListener) { window.addEventListener("load", track, false); }
else if (window.attachEvent) { window.attachEvent("onload",track); }
else {
track();
} |
@tsteur you shouldn't need the IIFE inside of track. It's superfluous because the track function is already providing the lexical scope. |
True, changed it. It was implemented a bit different first and then just copied into the track function :) |
tentatively adding to 3.0.0 milestone - it would be a nice improvement to have 👍 |
?? |
@hpvd yes, I'm sure that my pages appearing to load as fast as they'd without piwik is more important to me than 100% accuracy. If you want 100% accuracy, you might end up with the opposite effect: you'd lose some users who're dissatisfied with your site's performance, and you'd have a perfect measurement of the ones with patience. It's basically the web version of the observer effect. |
@pekeler thanks for your answer.
One can decide to do it this way, but it should not be standard solution in Piwik. |
I guess the point is with correct server setup etc you can have your There are different caching strategies possible which can be all configured server side and depends on how the file/tracking code is included into the page. For example if someone wants aggressive caching for best page load speed (which is critical for some websites / shops) they can do that and they maybe don't mind if it takes a while until a new version to |
We recently documented this in our blog post:
And in the FAQ: |
Moved here from the forum as suggested by @mattab
While the JS-loading snippet doesn't delay when the page is usable, it does appear to delay it because the browser's page-loading indicator is on/spinning until after piwik.js has been loaded. So if it takes 5 seconds to load piwik.js, it looks to the user like piwik is slowing down the page load by 5 seconds. This can be improved by delaying the loading of piwik.js until after the onload event.
The downside of this approach is that if someone navigates quickly from page to page, there's now a slightly bigger chance of piwik not tracking it. But I think speed is more important than accuracy.
If you still care about IE 8 and below (you really shouldn't anymore), you'll need to do that dance with
attachEvent
. And if you're cool with ignoring IE 9 and below, you can drop thepart.g.async=true;
I meant: "if you're cool with ignoring IE 9 and below, you can drop the
g.defer=true;
part."The text was updated successfully, but these errors were encountered: