Adding and Testing Google Analytics Tracking Code
One reason that Google Analytics has gained such rapid popularity is its ease of implementation. Google made the installation process easy enough that non-technical website owners have been able to use it.
For most websites, simply copying and pasting the code that Google provides is sufficient. It's important to be able to test that code implementation immediately, though. Sometimes it's even necessary to go back into the account to grab the code again.
Does your company keep a backup of your Google Analytics data? If not, start today.
Where is the Code?
If you need to get that code again after that initial setup process, you'll need to hunt. First, go to the edit screen for the profile in question. From there, click "Check Status" in the upper-right corner of the screen. This brings you right back to the page with code and instructions for implementing it.
Where Does the Tracking Code Go?
The tracking code needs to be pasted into the HTML code for each page of your website. If you use a CMS like WordPress / Joomla / Drupal, there is likely a plugin or module you can install that will insert the code automatically. If not, your web server probably has a global footer template that affects every page of your site.
Paste this code into the footer directly above the closing head tag. That said, the code is asynchronous and can be placed anywhere in the page.
The standard implementation works for most websites. There are a few scenarios that require some modification to the tracking code before you put it into your site. If your site is an ecommerce site, uses multiple subdomains or if it spans multiple domains (e.g., during a checkout process), you will need to make some changes.
Our tracking code generator creates custom code for the most common scenarios.
Testing the Implementation
Google Analytics may display a warning icon next to your profile indicating that the code is not set up correctly until it begins to receive data. Data can take up to 24 hours to populate, but we've never seen it take that long! The warning icon will go away once data begins to feed into the account.
At this point, you may want to check a few things to make sure your code is implemented correctly.
Before anything else, make sure the UA number in the code is the same as the UA number for your profile. View the source of a page on your site, search for "analytics" (no quotes), and look for a string that looks like this:
That UA number should be identical to the one for your profile. Confirm by going to the list of your profiles in your Google Analytics account. The UA number is listed next to each one.
Google Analytics sets four cookies on each visitors' machine by default. They are named __utma, __utmb, __utmc and __utmz. There are multiple add-ons for Firefox that will allow you to read the cookies on your browser. If any of these cookies are missing, the tracking code isn't loading correctly.
The tracking code sends all of the information to your Google Analytics account via a file request to www.google-analytics.com named __utm.gif. It will have a long query string (question mark followed by variables) that contains all the pageview and visit information. You can use the Chrome, Firefox, or Internet Explorer developer console to see if the file is being requested. If it is, your code is working fine. It's gathering all the information, setting cookies and sending it all to your account.
If the __utm.gif file is not being requested, it means the tracking code isn't loading correctly.