As you might expect, you do need to sign up for Google Analytics if you haven’t already done so. I recommend using a Google account, as it makes it easier to include other marketing products such Adwords, Adsense and Webmaster tools.
Where to find the google analytics tracking code
- In the analytics user interface, click on the Analytics settings button. It is the gear icon that you find to the right of the menu bar.
- If you happen to have more than one account, then you will have to click on the appropriate account and the website/profile you are working on. The tracking code is profile and website specific, so make sure that you have correct website selected.
- Click on the “tracking code” tab on top
- Click on the “standard” tab next
- On the first section which says “What are you tracking“, select the appropriate selection for your scenario. Most likely you would select the first option, which is “a single domain“.
- In the second section, in the text box you will find the code that you will use on your website.
- Copy the code from the text box
Where to insert the tracking code in the website
In your website, you have to insert the tracking code into each and every webpage that you would like to track. If you happen to have a lot of pages, it is not a easy task. Moreover there are some reasons why you should refrain from inserting the same piece of code into each of the webpages individually.
- It is difficult to maintain in the long run as you will have to remember to insert the code into every new page you will create in future
- If the code changes in future, as it most likely will, then you will have to change each and every page in your website
- If you have many pages, then it is more likely that you will make a mistake and not realize it.
The best way to do it is to put it in a common or “include” file and then insert that file programmatically into every page. Usually you should have an include file already where you put all the common code snippets, of course depending on how it is designed. This is probably the most efficient and easiest way to do it.
There are actually two versions of the code available, namely the synchronous/traditional version and the asynchronous version. The asynchronous version is the latest and the only version you should be using. There is no reason to use the older synchronous version and it is only supported for legacy reasons. There are several advantages to using the latest asynchronous version.
- Faster page loading compared to the previous version. The google tracking code itself is supposed to load faster without blocking the rest of the page.
- Do not require additional code to track SSL or secure pages
- Problems at the google servers should not affect the performance of your website
- Better data collection even when the users leave early in the loading process.
Google recommends that you place this code just before the end of head tag (</head) in the webpage. It should still work wherever you put it, but it just gives a better performance and track even users who leave early before the page is fully loaded.
If you are using a CMS such as WordPress, then you do have other options available to insert tracking code such as plugins to make it a little more seamless. I still prefer to add the tracking code manually such it eliminates the need for a separate plugin in WordPress.