Analytics Market Chart

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.

Where is the Code?

When you first create a profile, you are presented right away with a screen that instructs you to copy and paste the code into your website. Below those instructions is a text box with JavaScript 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.

Exceptions

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.

Besides these required changes, there are some more advanced modifications that can be made using built-in JavaScript methods that are outside the scope of this article.

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.

UA Number

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:

("UA-39341144-1")

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.

Cookies

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.

__utm.gif Request

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.

If you can see that ga.js is being requested from the same server but not __utm.gif, it indicates a problem in the second block of JavaScript. If neither are being requested, it indicates a problem with the first block of JavaScript. In either case it's usually a syntax error. Usually this is the result of modifications to the code that were done incorrectly or the code being reformatted by an email client. If you copy and paste the tracking code into an email, it may get reformatted when it's sent. If you must email the code, try copying and pasting into a text document and attaching that to your email.