Tracking Websites with Universal Analytics

Universal Analytics is the evolution of Google Analytics. In addition to tracking mobile apps and almost any other device. Let’s tracking websites with Universal Analytics and demystify how the tracking works.

Note: if you’re a beginner, and you just want to get started, all you need to know is this: get the Universal Analytics tracking code from the Tracking Info portion of the Admin Section.

Place the Universal Analytics tracking code on every page of your site.

Place the Universal Analytics tracking code on every page of your site.

After you copy the code, past it into the HEAD section of your website. If you use some type of template just add it to the template.

Location for the Universal Analytics tracking Code

Put the Universal Analytics tracking code in the HEAD section on all the pages of your site.

Once you’ve added the tag to your site you should start to see data in the Real Time reports. Google Analytics processes data about every 4-ish hours. So the standard reports will be populated about 4 hours after the code is install. But it can sometimes take up to 24 hours for data to appear.

Using the basic tag you’ll get a lot of data including:

  • Visitor count
  • Number of visits
  • Pageviews
  • Geographic location of your visitors
  • Referral information
  • Device information

For those that want a little more insight into how Universal Analytics works for a website, keep reading.

The Universal Analytics Page Tag

Like the previous version of Google Anlaytics, Universal analytics uses a JavaScript page tag to track a website. Here’s what the tag looks like:

< script >
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-YYYYY-XX', 'cutroni.com');
ga('send', 'pageview')
< /script >;

NOTE: The tag for your site will look different. Specifically the account number, which is UA-YYYYY-XX will be different, and the domain name appearing after the account number will also be different. More on this below.

The page tag consists of two parts.

1. First, a request to the Google Analytics servers for a code library. It’s named analytics.js.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

For you coding nerds, you’ll notice that the library has changed names, from ga.js to analytics.js.

One difference that you can not see is that analytics.js does NOT contain any ecommerce code. That code is stored in a separate file that you use when you track a transaction. By splitting out the ecommerce code it helps the tracking code load faster on your site and speeds up your site (a little bit).

Also notice that new tracking code is asynchronous, just like the previous tracking code. This means that your website page will load while the Google Anlaytics tracking code is loading. You don’t need to worry about the code slowing down your page and causing a bad user experience.

2. The second part of the code is a list of actions.

ga('create', 'UA-YYYYY-XX', 'cutroni.com');
ga('send', 'pageview')

There are two actions.

First Google Analytics connects this tag to your account. That’s done via the create command. It creates something called a tracking object to connect the data that is sent to your account on the server.

Once the tracking object is create the code sends a data hit, in this case a pageview, back to Google Analytics.

You’ll also notice that the syntax has changed. There are no longer functions like _trackPageview. Now you ‘send’ or ‘create’ hits. Each type of hit has a different commend.

To track a website add the page tag, which is ALL of the code above, to all of your pages. To get the most accurate data, you should add this code to the HEAD section of your site.

Universal Analytics Tracking Cookies

Universal Analytics uses a single, first-party cookie to track visitors.

Universal Analytics uses a single, first-party cookie to track visitors.

To track users on a website Universal Analytics uses a first party cookie, just like the previous version of Google Analytics. The big difference is that Universal Analytics uses ONE cookie while the previous version uses four (and sometimes five) cookies.

This reduction of cookies means that your site should be a bit (a tiny bit) faster.

The new Universal analytics cookie is named _ga and looks like this:

_ga=1.2.838838867.1359565579161

Note: Did you know you can actually rename the tracking cookie in Universal Analytics?

The main reason that there is a cookie is to identify the user. This is done by generating an anonymous, random number and storing it in the cookie. This number is sent on every hit to the Google Analytics server and is used to calculate visits, visitors and campaign metrics.

The cookie will last on the visitor’s computer for two years. The expiration date will get pushed back two years every time the visitor hits the site. You can change the duration of the cookie using JavaScript.

For the nerds, changing the cookie expiration is different than changing how long a duration will last. Visit duration and timeout is configured in the Admin section of Google Analytics.

It’s also important to note that this cookie will work for all of sub-domains of your website. In the previous version of Google Analytics you needed to change the code to track users across sub-domains. You do NOT need to change the code in Universal Analytics.

This can be a lot to absorb, but one more thing :)

You may want to consider using Google Tag Manager to implement Universal Analytics.

A tag management tool, like Google Tag Manager, helps you avoid any coding changes to your site. You basically manage all your tags from a handy web interface.

You can also use Google Tag Manager to track events, ecommerce transactions, etc. In general, using GTM, or any tag management tool, is strongly suggested.

If you do decide to use a tag management tool, don’t forget to consider adding a data layer.

That’s about it for the basics. But there are a lot of different types of configurations that can help you customize the data for your business. These are fodder for another post.

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.

    Comments

    1. Tatiana says

      Justin, what are the key updates of the universal analytics tracking, apart from actual formatting of the code. I mean, regarding features. Now I can get only the changes about subdomain tracking. Any other global updates in functionality?

      • says

        Tatiana: Everything related to website tracking has changed. The analytics.js tracking code is a completely new tracking tag. This means that every JavaScript method has changed. That include cross domain tracking, sub domain tracking, ecommerce tracking, event tracking, social tracking, custom time tracking… everything. If you’re using GA on a site, and you want to track that site with UA, you need to change ALL of the JavaScript. My recommendation would be to wait until you can migrate a GA web property to UA.

        Hope that helps.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>