Sunday, December 6, 2009

Google Analytics new asynchronous tracking code

Google Analytics has now provides new asynchronous tracking code. The main feature of the asynchronous code is that it could load ga.js while the page is being rendered.

There are two ways to use this code.

  1. Place the code below before the  </head> tag.
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
     _gaq.push(['_trackPageview']);  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '.google-analytics.com/ga.js';  
       ga.setAttribute('async', 'true');  
       document.documentElement.firstChild.appendChild(ga);  
     })();  
     </script>  
    

  2. Split the code. Half of the code will be put before the </head> tag. Another half will be put at the end of the page, before the </body> tag.
    The first half (before </head> the tag).
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
     _gaq.push(['_trackPageview']);  
     </script>  
    
    The second half (before </body> the tag).
     <script type="text/javascript">  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '.google-analytics.com/ga.js';  
       ga.setAttribute('async', 'true');  
       document.documentElement.firstChild.appendChild(ga);  
     })();  
     </script>  
    

Note:

  1. Remove any existing Google Analytics code before using this asynchronous code.

  2. Disable any Google Analytics plugin (if you use one) for WordPress.

  3. Replace UA-XXXXX-X with your web property ID.

1 comment :

  1. Pls i just formated my nokia E71 by holdn call button,*,3 and have tried d lock code 12345 is not workn.is telln me code error. Pls hw do i get a new unlock code to open my phone? U can email me on (promisealaehie@yahoo.com) tanx urgently

    ReplyDelete