2014-09-26 68 views
0

我按照我的html代碼:hitCallback不與斷開,Ghostery的,等工作

<a href="/register/" onclick="var href=this.href;ga('send','event',{'eventCategory':'Registration','eventAction':'clickRegister','hitCallback':function(){document.location=href;}});return false;">Sign up</a> 

它不工作然後斷開或類似的插件安裝在Chrome或其他瀏覽器。如何解決這個問題?我已經使用

回答

0

解碼的通用Analytics(分析)代碼版本,並把那裏調用hitCallback:

<!-- Google Analytics --> 
<script> 
    /** 
    * Creates a temporary global ga object and loads analy tics.js. 
    * Paramenters o, a, and m are all used internally. They could have been declared using 'var', 
    * instead they are declared as parameters to save 4 bytes ('var '). 
    * 
    * @param {Window}  i The global context object. 
    * @param {Document} s The DOM document object. 
    * @param {string}  o Must be 'script'. 
    * @param {string}  g URL of the analytics.js script. Inherits protocol from page. 
    * @param {string}  r Global name of analytics object. Defaults to 'ga'. 
    * @param {DOMElement?} a Async script tag. 
    * @param {DOMElement?} m First script tag in document. 
    */ 
    (function(window, document, strScript, url, variableName, scriptElement, firstScript) { 
    window['GoogleAnalyticsObject'] = variableName; // Acts as a pointer to support renaming. 

    // Creates an initial ga() function. The queued commands will be executed once analytics.js loads. 
    window[variableName] = window[variableName] || function() { 
     (window[variableName].q = window[variableName].q || []).push(arguments); 

     // If user uses Disconnect, Ghostery, DoNotTrackMe or similar plugin we shoud make hitCallback to work 
     if(typeof arguments[2] == "object" && typeof arguments[2].hitCallback == "function") { 
     arguments[2].hitCallback(); 
     } else if (typeof arguments[5] == "object" && typeof arguments[5].hitCallback == "function") { 
     arguments[5].hitCallback(); 
     } 
    }; 

    // Sets the time (as an integer) this tag was executed. Used for timing hits. 
    window[variableName].l = 1 * new Date(); 

    // Insert the script tag asynchronously. Inserts above current tag to prevent blocking in 
    // addition to using the async attribute. 
    scriptElement = document.createElement(strScript), 
    firstScript = document.getElementsByTagName(strScript)[0]; 
    scriptElement.async = 1; 
    scriptElement.src = url; 
    firstScript.parentNode.insertBefore(scriptElement, firstScript) 
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); 

    ga('create', 'UA-XXXXXXXX-1', 'auto'); // Creates the tracker with default parameters. 
    ga('send', 'pageview'); // Sends a pageview hit. 
</script> 
<!-- End Google Analytics -->