About this guide

Universal Analytics is currently the new version of Google Analytics (recently out of beta), which includes many new & great features. However, new features come at the cost of new code and the need to rewrite some items. The goal of this guide is to help developers understand the difference between the code bases. Look for the icon for links directly to Google's official documentation for that subject.

Note: As of April 2014, analytics.js (Universal Analytics) includes all of the features that ga.js (older Google Analytics) and now allows upgrading ga.js reporting to analytics.js reporting!

Google has released the official code migration guide.

The Basics

This chapter goes over the overall basics that you'd find within every single implementation. Items covered:

  1. The code block included on every page
  2. _setAccount
  3. _trackPageview
  4. Multiple Accounts

Configuration

This chapter goes over some of the more common options. Items covered:

  1. _setDomainName
  2. _setCookiePath
  3. _setSampleRate
  4. _setSiteSpeedSampleRate
  5. _setVisitorCookieTimeout

Event Tracking

This goes over both the _trackEvent and _trackSocial methods:

  1. _trackEvent
  2. _trackSocial

Ecommerce

This chapter details methods related to ecommerce tracking. Items covered:

  1. _addTrans
  2. _addItem
  3. _trackTrans
  4. A full example of a shopping cart confirmation page
  5. _clearTans

Display Features

This goes over the remarketing features.

  1. Cookie Name
  2. Multiple Trackers

Custom Variables

This chapter only covers one item: _setCustomVar

Other Items

This chapter goes over things that didn't really fit in other chapters. Items covered:

  1. Cross domain tracking
  2. _trackTiming
  3. _anonymizeIp

Change Log

Below is a brief overview of the changes made to the content of this guide. You can find the full history on the Github repo.

Added remarketing configuration
Updated to reflect that analytics.js is now out of beta
Added a few extra comments within some of the code blocks
Added _clearTrans
Clarified this is not about data migration, just code migrations
Fixed Ecommerce code samples to include the price property
Added tracker name property