Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Latest Approach : </p> <ol> <li>We allow ga to load normally.</li> <li>We store a reference to ga dom element in a global variable (gaClone).</li> <li><p>We set a timeout of 30seconds. We also set another global variable (loadedGoogleAnalytics) and set it to 0 initially. When ga loads, we set this variable to 1. On the timeout expiry, we check whether ga was loaded or not. If not, we delete the dom element ga.</p> <pre><code>&lt;script type="text/javascript"&gt; var loadedGoogleAnalytics = 0; var gaClone; var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456789-1']); _gaq.push(['_trackPageview']); _gaq.push(function() { loadedGoogleAnalytics = 1; //console.log('GA Actualy executed!'); }); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); gaClone = ga; })(); setTimeout(function() { //console.log('timeout fired'); if (loadedGoogleAnalytics != 1) { gaClone.parentNode.removeChild(gaClone); } }, 30000); &lt;/script&gt; </code></pre></li> </ol> <p>[I have verified this approach with one of my actual GA accounts and i am able to see all the realtime tracking]</p> <p>Previous Approach [Note: Ga does not execute if we try to place it in (document).ready();] [This solution does not work]</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456789-1']); _gaq.push(['_trackPageview']); srcUrl = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; $.ajax({ url: srcUrl, cache: true, dataType: "script", success: function(data) { //console.log('got the script'); }, error: function() { //console.log('failed to get the script'); }, timeout: 30000 }); }); &lt;/script&gt; </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload