Posted By

krisdb on 02/13/08


Tagged

javascript


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

adix
vbert
joomla


Google Analytics code


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2. var gaJsHost = (("https:" == document.location.protocol) ?
  3. "https://ssl." : "http://www.");
  4. document.write(unescape("%3Cscript src='" + gaJsHost +
  5. "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  6. </script>
  7.  
  8.  
  9. <script type="text/javascript">
  10. // Gives us an easy way to tell if an item is in the array
  11. Array.prototype.inArray = function (value) {
  12. var i;
  13. for (i=0; i < this.length; i++) {
  14. if (this[i] === value) {
  15. return true;
  16. }
  17. }
  18. return false;
  19. };
  20.  
  21. // Set up our array of valid host names
  22. hostArray = new Array('www.DOMAIN.com','DOMAIN.com');
  23.  
  24. // If the current host name is in the array, send the tracking info to Google
  25. if (hostArray.inArray(window.location.hostname))
  26. {
  27. var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
  28. pageTracker._initData();
  29. pageTracker._trackPageview();
  30.  
  31. }
  32.  
  33. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chrisaiv on February 13, 2008

Heads up, Google now offers a new tracking code called ga.js. It offers a lot of new features such as analytics for internal search engines.

Posted By: joomla on July 10, 2008

good job, saves a buncha time

You need to login to post a comment.