Troubleshooting Google Analytics 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?

When you first create a view, you are presented 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.

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 loads asynchronously 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.

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.

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. Click a few pages on your site and open the real time reports to see your traffic.

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.js” (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 a few on each visitors’ machine by default. The cookie names begin with _ga. Use the browser console (press F12 on your keyboard) to view cookies created by your website – if the _ga cookies are missing, the tracking code isn’t loading correctly.

/collect Request

The tracking code sends all of the information to your Google Analytics account via a request to 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 (press F12 on your keyboard) 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 /collect request is not being made, it means the tracking code isn’t loading correctly.

If you can see that analytics.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.

Next Steps

Check out our Recommended Tools to learn about products that complement Google Analytics.