Page generation times in js code #4282
Labels
Enhancement
For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Major
Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
worksforme
The issue cannot be reproduced and things work as intended.
I am working with Drupal, and optimizing my server for fast page generation times, because Google officially said, that it will show sites, that loading faster, above than other sites.
Also page rendering and end-user loading is important.
I want to include this info to my piwik stats.
I tried to find and found something about that.
https://github.com/uamuzibora/nafasi/wiki/Page-load-times
http://www.html5rocks.com/en/tutorials/webperformance/basics/
and found some old ticket, and a removed commit here:
uamuzibora/nafasi@b8e3dc1
I am using Drupal's Piwik module, and my js code much differs from that.
How to mix these codes to have all times in my piwik database?
More important are page generation (I can include it from php if needed) and rendering/total page loading
My code is:
<script type="text/javascript">
var _paq = _paq || [];
(function () {
var u = (("https:" == document.location.protocol) ? "https://domain.com/pwstat/" : "http://domain.com/pwstat/");
_paq.push("1");
_paq.push(u + "piwik.php");
_paq.push(".domain.com");
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.type = "text/javascript";
g.defer = true;
g.async = true;
g.src = "http://domain.com/sites/default/files/piwik/piwik.js?mu3pia";
s.parentNode.insertBefore(g, s);
})();
</script>
But the code with times is:
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://192.168.1.2:8080/" : "http://192.168.1.2:8080/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
window.onload = function(){
setTimeout(function(){
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
var t = performance.timing;
var totaltime = t.loadEventEnd - t.navigationStart;
var networktime = t.requestStart - t.navigationStart;
var servertime = t.responseStart - t.requestStart;
var downloadtime = t.responseEnd - t.responseStart;
var browsertime = t.loadEventEnd - t.responseEnd;
var n = performance.navigation;
var navtype = n.type;
if (navtype == 0)
{
piwikTracker.setCustomVariable (1, 'Page Load Time', totaltime, 'page');
piwikTracker.setCustomVariable (2, 'Network Time', networktime, 'page');
piwikTracker.setCustomVariable (3, 'Server Response Time', servertime, 'page');
piwikTracker.setCustomVariable (4, 'Page Download Time', downloadtime, 'page');
piwikTracker.setCustomVariable (5, 'Browser Time', browsertime, 'page');
}, 0);
}
} catch( err ) {}
</script><noscript><p><img src="https://192.168.1.2:8080/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
So it uses window.onLoad, but my code not And is this code full? or it is missing something? I read about API that measures these times
How to combine it?
The text was updated successfully, but these errors were encountered: