kotmyrevich / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Bug in code in Analytics for Web (analytics.js) #747

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
---------------------------------------------------------------------------
NOTE: This tool is not designed to request help. It is only for reporting
issues and requesting features for the Google Analytics libraries.

If you are a developer and you need help, visit:
https://developers.google.com/analytics/help/

If you are not a developer and you need help, visit:
https://support.google.com/analytics
---------------------------------------------------------------------------
Name of related component: Documentation

URL of the documentation page : 
https://developers.google.com/analytics/devguides/collection/analyticsjs/sending
-hits#handling_timeouts

Issue summary:
There is a bug in the sample code here that would result in the form being 
submitted twice.  The problem is with the code in the function 
createFunctionWithTimeout().  If left like it is, then the callback function 
passed to it will be invoked every time the timeout number of milliseconds 
expires, since it does not perform the check to see if the callback was 
executed after the hitCallback is invoked after the send.  It should really 
look something like the following:

function createFunctionWithTimeout(callback, opt_timeout) {
    var called = false;

    var invokeCallback = function() {
        if (!called) {
            called = true;
            callback();
        }
    };

    setTimeout(invokeCallback, opt_timeout || 1000);
    return invokeCallback;
}

Notes:
Provide any additional information which might be useful here. Feel free to
attach screenshots.

Original issue reported on code.google.com by pecan.software@gmail.com on 3 Oct 2015 at 5:19