Setting gt_ms measure for IE8 users

Hello all,

I’m using Piwik 1.12 for our intranet applications, and most of our users are using Internet Explorer 8 (the standard here, unfortunately).
On the Piwik dashboards, the “Average Generation Time” column is not filled for these users.
After some investigations, I found that this feature requires the performance.timing API, which is only implemented in IE9+ (cf. ticket 1700).

At the end of this page, it is said that

If you use the Tracking API directly you can specify the page generation time (in milliseconds) in the gt_ms query parameter.

It seems that the only way for me to fill the gt_ms information for IE8 is to calculate it by myself. My question is how to do that, and how to give this information to Piwik?

Thanks in advance.

I finally found a solution.

First, on my template page, I add this:

        <!--[if lte IE 8]>
            <script src="/public/javascripts/piwik-extension.js'" type="text/javascript" charset="UTF-8"></script>

This script only contains a declaration of a variable with the timestamp:

var PIWIK_startingTime = new Date().getTime();

In the code snippet for Piwik tracker, I put that:

<script type="text/javascript">
    var _paq = _paq || [];

    // Detection of Browser name and version
    var whoIam = navigator.sayswho= (function(){
        var ua= navigator.userAgent,
                N= navigator.appName, tem,
                M= ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*([\d\.]+)/i) || [];
        M= M[2]? [M[1], M[2]]:[N, navigator.appVersion, '-?'];
        if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
        return M.join(' ');

    // Check if the browser is IE6, IE7 or IE8...
    if (/MSIE [6,7,8]/.test(whoIam)) {
        // In that case, calculate manually the gt_ms (Average Generation Time)
        var avg_gt_ms = new Date().getTime() - PIWIK_startingTime;
        _paq.push(["setGenerationTimeMs", avg_gt_ms]);


It works on IE8 now.

If you have a better solution, please share it, I would be happy to see it.

This generation time is different from the one processed by Piwik by default. The time processed by piwik includes the server time generation.

Ok, thanks for this important precision.

Is there a way to calculate that information on IE8 ?

One idea is to generate a timestamp when the client sends a request to the server (PIWIK_startingTime), add this information in the request itself, and when the server generates the response, it includes the generated timestamp in the response. Thus, the client will calculate the generation time using this PIWIK_startingTime value, so it includes the time needed by the server to generate the page.

Is there a better solution?