Avoid the Facepalm: 5 Common Mistakes in Your Google Analytics Tracking Code



When something’s broken and you can’t figure out how to fix it, there’s nothing like that feeling of sheepish chagrin after you discover it simply wasn’t plugged in. Believe it or not, we see the equivalent of “not plugged in” pretty often when troubleshooting broken implementations of Google Analytics.

Avoid the d’oh moment: Check your Google Analytics tracking code for these 5 common mistakes.

Mistake #1 – Code is missing

Besides simply overlooking some pages during your initial implementation of tracking code, code can turn up missing because:

  • New templates didn’t get code
  • Special campaign landing pages didn’t get code
  • Code was inadvertently deleted during edits to other parts of a template or page
  • Code from your Dev site without GA was pushed live

GA notification about missing tracking code

Best practice #1 – Get everyone on board

Have a process in place to ensure that all team members are aware of your tracking code and know where to place the Google Analytics code or where to place Google Tag Manager code on new templates or pages.

Mistake #2 – Code is duplicated

Perhaps someone accidentally pastes the new code twice or, more likely, code can be duplicated because something goes wrong during migration to a new implementation of Google Analytics.

Frequently, one code snippet is near the top of the page, while the other piece of code is near the bottom. Even if they’re right next to each other, you may find:

  • Google Tag Manager (or another tag management system) is sending hits to GA and code on the page is also sending hits to the same GA property (the same UA ID number)
  • Classic GA code and Universal Analytics code are both sending hits to the same GA property

There’s a great Chrome Extension called Google Tag Assistant that will help call out this mistake and other mistakes.


Best practice #2 – Test and monitor code changes

Any time new code is implemented, use browser developer tools to ensure that only a single pageview is tracked on each page as intended, or if multiple pageviews are tracked, then they should be sent to different UA numbers. Old code should be removed or directed to a separate UA number.

More technical users will remember that the Classic GA code sends its hits to http://www.google-analytics.com/__utm.gif, while Universal Analytics sends its hits to http://www.google-analytics.com/collect.

Chrome Developer Tools Network Tab

Chrome Developer Tools Network Tab

Bonus tip: Monitor data in Google Analytics following the implementation to watch for drops in bounce rate caused by an extra hit on each page.

Bounces are sessions with only a single hit, typically from viewing a single page. Bounce rate will plummet when pages send two hits to Google Analytics each time they are loaded.

Mistake #3 – Automatic events affect bounce rate

In addition to duplicated code, automatic events can also make bounce rates artificially low if they send a hit every time a page is loaded. Examples:

  • Internal promotions
  • Partner ads
  • Modal windows

Best practice #3 – Use non-interaction events

If a user is not intentionally interacting with your site, track a non-interaction event to keep bounce rates accurate (and useful).

Mistake #4 – Subdomain tracking is missing

Do your users travel between subdomains like blog.mydomain.com and microsite.mydomain.com? If you don’t implement subdomain tracking, Google Analytics will identify User A as User B on the second site – which will also create a second session.

Google Analytics writes cookies to identify each user and, by default, cookies are written to the full domain (with the exception of “www”). You should not rely on the default if you want to track users across subdomains, for example:

  • Users who start on mydomain.com and end on shop.mydomain.com or donate.mydomain.com
  • Users who go back and forth between subdomains (or your main domain), such as news.mydomain.com, investors.mydomain.com, or products.mydomain.com

GTM Fields to Set

Best practice #4 – Set the cookie domain to ‘auto’, add referral exclusion

Setting the cookie domain to ‘auto’ will write cookies to mydomain.com, allowing them to be read by the main domain and all subdomains of mydomain.com. This way User A will be identified as User A across subdomains and not start a second session.

Universal Analytics Code on Page

Lastly, verify that your domain is listed in the Referral Exclusion list. For more information, check out our guide: Two Steps To Correctly Tracking Subdomains in Google Analytics

Exception: If you want to track a second session each time a user travels across subdomains, stick with the default, which will tell you that sessions starting on mydomain.com were actually referrals from a subdomain like blog.mydomain.com.

Mistake #5 – Cross-domain tracking is missing

Do your users travel from mydomain.com to myotherdomain.com? In this case, subdomain tracking won’t help you. You need cross-domain tracking to make sure that User A is still identified as User A and to avoid starting a second session in your analytics data.

If both of these websites are tracked into the same Google Analytics property (they have the same UA number on them) then you’ll end getting multiple sessions and users as someone moves between the two or more sites.

Best practice #5 – Set up cross-domain tracking

There are two parts to cross-domain tracking:

  • Push the _ga cookie to the URL of the link that was clicked on Domain A, i.e. “decorate the link”, and
  • Read the cookie from that URL on Domain B. (And vice-versa, decorate links on Domain B and read cookies on Domain A.)

URL decorated with _ga cookie for cross-domain tracking

Cross-domain tracking fails because one of these components is missing.

Google Analytics knows this is a common issue, so they’ve built in a process to make it easier. There are different commands you can use to tell GA to pass the cookie when a user clicks on websites you determine, and then another command that allows the tracker on the second website to use the passed _ga value instead of creating a new one.

It sounds complicated because…. well… it is! Setting it up right may require that you hire expert assistance. It can be less complicated, but not necessarily a snap, with cross-domain tracking in Google Tag Manager.

What mistakes have you seen more than once? Have you had any facepalm moments? Please share in the comments.

Dorcas Alexander is a Manager for the Analytics & Insight department. Her path to LunaMetrics followed stints in ad agency creative, math, and computer science. Dorcas has a master's degree in language and information technologies from Carnegie Mellon University, where she helped build precursors to a Universal Translator. One of the top-rated tournament Scrabble players in Pennsylvania, Dorcas has an insatiable drive to compete and win.

  • Hello,

    Where can I find the setting for #4 “Set the cookie domain to ‘auto’”?

    • Dorcas Alexander

      Hi Matt, I included screen shots to show how to do this either in code on the page or in Google Tag Manager. I guess those images must not have loaded for you, so here’s where to find that info. For code on the page, look at the following documentation (scroll down to the section titled “Automatic Cookie Domain Configuration”): https://developers.google.com/analytics/devguides/collection/analyticsjs/domains. And if you’re using Google Tag Manager, inside each tag you should look under “More Settings” and “Fields to Set”. There you should enter cookieDomain as the Field Name and auto as the Value.

      • Marian Popovych

        Thank you!
        I’ve thougt I should look for this option in the UA interface.

  • Tatiana Saburova

    Hi, can you help me please? If i set the cookiedomain: ‘auto’ for the website A but for the website B it was set up ‘cookieDomain: ‘none’ – is the crossdomain tracking will be ok?

    • Dorcas Alexander

      Hi Tatiana, It depends on whether you are doing true cross-domain tracking or whether you only need to do sub-domain tracking. If website A and website B share the same primary domain, e.g. store.examplesite.com and blog.examplesite.com, then both need to have cookiedomain: ‘auto’ which allows you to do sub-domain tracking. If website A and website B do not share the same primary domain, then you need to do true cross-domain tracking, and you need more than a cookiedomain setting. Read a good explanation here: http://www.lunametrics.com/blog/2015/06/16/cross-domain-tracking-with-google-tag-manager/

      • Tatiana Saburova

        Hi, Dorcas!

        Thank you for your answer. The materials are really very interesting. But i still have my question.

        I have two different websites: website A and the cart B.
        Cart B is managed by Asknet and we can’t use our GTM there. They install our GA-tracker by their own way.
        At the site A we use GTM and the crossdomain tracking works alright with all other carts that we have.
        So, looking at their code i see that they haven’t installed allowLinker:true and install cookieDomain as ‘none’. After they add allowLinker the sources are still losing. And i’m interesting can the problem be connected with cookieDomain:none? For our website A we use cookieDomain:auto.

        And that’s why I’m ineteresting what happens when cookieDomain:auto at websiteA is changed by cookieDomain:none at website B?

        • Dorcas Alexander

          Hi Tatiana, What happens in that case is you will have data from both websites, but the data will appear in GA as part of separate sessions for different users. You will not see User 123 with a session that contains both website A and cart B. GA will not have any way to know that they are supposed to be part of the same session, because the cookies are not being shared from one site to the other.

          • Tatiana Saburova

            Dorces, thank you very much. So, a should set cookieDomain:auto for both websites?

            I’m interesting because in GA developers guide they advise for 1st website set: cookieDomain:auto and allowlinker:true, and for the cart just allowLinker:true. There is no information about setting cookieDomain for the second website. So, i think that in this case cookieDomain for the cart will set by default (or maybe will be taken from the first site?). I can’t understand what is the default meaning for cookieDomain at Universal GA. Can you help with it?

          • Dorcas Alexander

            cookieDomain:auto will work only if cart B has the same primary domain has website A, like cart.mysite.com and http://www.mysite.com. If cart B is mysite.cartsite.com and website A is http://www.mysite.com, then you need more code like in the article I linked.

  • KMorris

    Hello, I really enjoyed your article, but have a little spin on subdomain traffic. How would you recommend I setup analytics on subdomains to track activities between first time visitors vs existing customers?

    Traffic 1: maindomain.com and blog.maindomain.com
    Traffic 2: .maindomain.com (Customer traffic after purchase/subscription)


  • Shaukat Ali

    Google Analytics code keeps disappearing on my blog http://www.pifeed.net, even after small changes like widgets rearrangement in the sidebar….

Contact Us.

Follow Us




We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187