How do I add Google Analytics tracking code?

In order to use Google Analytics, you need to register an account first. Then create a website profile for it. Finally, you need to insert the tracking code into your website. There are 2 tracking codes currently – Legacy Tracking Code (urchin.js) and New Tracking Code (ga.js). Be sure to use the New Tracking Code (ga.js) because it can gain access to a wide range of exciting new features as they become available.

So where should I put it? You should put it into every webpage you want to track immediately before the </body> tag. Most of the websites use a footer template to display the bottom website layout. Just copy and paste the tracking code there.

Example, put the code right before </body>

<script type=“text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “’ type=’text/javascript’%3E%3C/script%3E”));
<script type=“text/javascript”>
var pageTracker = _gat._getTracker(“UA-xxxxxxx-x”);

  • footer.php?
    oic, got it! thank you so much for the info!

  • You are most welcome. 😀

  • Hi, do we have to paste all the codes in every page of our single domain or profile? All of the pages? Wow?

    Do we need to tell Google anaytic to track the addtional code that we add in later on for a single profile?
    Thanks 🙂

  • Yes. Paste it on every pages that you want to track.
    No need to ‘tell’ Google Analytics for additional code. 😛