Skip to content
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

Page generation times in js code #4282

Closed
vnevremeni opened this issue Nov 7, 2013 · 1 comment
Closed

Page generation times in js code #4282

vnevremeni opened this issue Nov 7, 2013 · 1 comment
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.

Comments

@vnevremeni
Copy link

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');

  }
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();

}, 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?

@mattab
Copy link
Member

mattab commented Nov 7, 2013

Please ask in http://forum.piwik.org/

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants