Google Analytics Decoded: The Code Snippets

Published:

By: Marc van Bree

In: Metrics & Analytics

At the 2015 National Arts Marketing Project Conference in Salt Lake City, UT, I had the distinct pleasure of presenting a session on Google Analytics with fellow ArtsHackers Drew McManus and Ceci Dadisman.

Google Analytics is a powerful tool. But it all depends on and starts with the proper code snippet. You may be building a new website or perhaps you have inherited a website that doesn’t yet have the tracking code, or perhaps you have a website that has the outdated snippet. Or you just want to check your current setup.

This article will go step-by-step through the basics of the Google Analytics snippet.

First things first.

Google Analytics Decoded The Code Snippets Admin Code

Where can I find the code snippet to add?

  1. Go to the “Admin” panel of your analytics account
  2. Under “Property” click on “Tracking Info” and then “Tracking Code”
  3. You will see the status: is it receiving data or not receiving data?
  4. You can copy the code to your clipboard to paste it in your website template files.

Where can I find the code snippet on my site?

[threecol_two]

  1. An easy way to check if it’s working is to check the status per above. Is Google Analytics receiving data or not?
  2. You can also do a spot check in the source code of your website.
    1. Right-click and select “View Page Source” or “View Source”
    2. Open the search box (Command + F for Mac, or Control + F for PC)
    3. Type in “google-analytics” and you’ll find a script that will look like the script your copied in the steps above.
    4. Ensure the ID in “ga(‘create’, ‘UA-xxxxxx-x’, ‘auto’);” is the correct ID

[/threecol_two] [threecol_one_last]

Google Analytics Decoded The Code Snippets View Page Source

[/threecol_one_last]

Where do I add or replace the code snippet?

Google Analytics Decoded The Code Snippets Site Code

Depending on your CMS, there are different ways of adding the code snippet. In WordPress, there are Google Analytics plugins where you simply add your ID in the admin panel and the plugin generates the code, or you can manually add it to your WordPress template files. In general:

  1. The snippet needs to go onto every web page you want to track. It is recommended you add it immediately before the closing </head> tag on your page.
  2. If you use templates to dynamically generate pages for your site (like WordPress, Joomla, Drupal or custom CMS platforms), you can paste the tracking code snippet into the template files, again before closing the </head> tag.

What are the different code snippets?

Legacy Code Snippet (Do Not Use!)

This was the first iteration of Google Analytics tracking code (ga.js), launched in 2005. When Google Analytics first appeared, the code was synchronous. That means the code must finish executing before the rest of the page can load. This can cause some slowdown and other issues loading your website. Later, the legacy code was updated to asynchronous code, which means the code loads in the background while the rest of you page continues to load.

Note: Legacy analytics code is officially deprecated. It is no longer updated and will eventually stop delivering data. Make sure you update your code.

Universal Analytics

Launched in 2012, universal analytics (analytics.js javascript) is the current code. This code snippet has features and benefits not available to legacy users (including, but not limited to, collecting data from different devices, connecting different sessions with a User ID, enhanced ecommerce tracking, etc.) and you will continue to get future updates through this snippet. If you have not done so, you need to update your legacy code to universal code.

Google Tag Manager

While universal analytics is the current code, Google has another way to manage Google Analytics code on your website. It is called Google Tag Manager. What are tags? Tags are tiny bits of website code from third-party services like tracking or advertising services.

The big benefit here is that you add a code snippet to your site once. Afterwards you the marketer can manage these tags from an interface, and you won’t need a web developer to keep adding new tracking codes to your site.

Stay tuned for the next post, where I’ll cover cross-domain and ecommerce tracking.

Photo of author
Author
Marc van Bree
I'm not a guru, maven or ninja or whatever the cool kids go by these days. I'm more interested in real solutions and getting things done. Backed by 10 years of results converting online and offline, building infrastructures and laying groundwork, and creating, running, and finessing marketing campaigns in a rapidly changing media environment. I have worked with and for a wide variety of businesses, startups, nonprofits and cultural institutions, including the Chicago Symphony Orchestra, Austin Opera, and Chorus Austin. During the day, I live in retail marketing, at night I run OvertureWP, a boutique managed web development and marketing company. I live just south of Austin, in Buda, Texas with my wife and two kids. When they’re asleep, I code for fun.
Author Archive

1 thought on “Google Analytics Decoded: The Code Snippets”

Leave a Comment