Hide

Reference - Complete Web Upgrade: Using Google Tag Manager

Overview

This guide helps Google Tag Manager (GTM) users upgrade their property configuration settings and tracking code from the classic Google Analytics tags and ga.js library to Universal Analytics tags and analytics.js library.

If you don't currently use GTM, refer to the Universal Analytics Upgrade Center Overview to choose the right upgrade guide for your development environment. To get started with GTM, see About Google Tag Manager (Help Center) and Developer Guide.

Before you Begin

This guide assumes you have already implemented GTM on your website and are using it to deploy classic Google Analytics tags.

If you are not yet using GTM, we recommend reading About Google Tag Manager (Help Center) and the Developer Guide before returning to this document to complete your Universal Analytics implementation using GTM.

If you are using GTM but not currently deploying Google Analytics tags, you may still use this guide to deploy Universal Analytics via GTM, but it will require familiarity with Google Analytics features and concepts. To learn more about any features described in this guide, consult the Google Analytics analytics.js Developer Guides.

Users who are upgrading from ga.js to analytics.js should review the following caveats before modifying their code:

  • The session timeout and campaign timeout periods must be configured via the Google Analytics Admin page, not in your code or tag template.
  • If you use multiple trackers on each page and are upgrading to Universal Analytics, expect to see a small, temporary increase of new users relative to return users after updating your tags. This is expected behavior and due to differences in the way sessions are processed in Universal Analytics.

Configuring Exclusions, Search Engines, and Timeouts

Begin the retagging process by migrating any necessary custom search engines or exclusions from your existing Google Analytics tags to the Google Analytics Admin page. The following sections document how to configure each of these settings from the Google Analytics Admin page.

Custom Search Engines

Google Analytics recognizes a number of search engines by default. If you want to add a custom search engine you can configure this from the Google Analytics Admin page. Any custom search engines that you have previously configured in ga.js using the the New Organic Traffic Source list in the Google Analytics tag templates should now be configured from the Google Analytics Admin page.

Referral Exclusions

Referring domains maybe be excluded from reports in Universal Analytics from the Google Analytics Admin page. Learn how to exclude referrals (Help Center). Any referral exclusions that you have previously configured in ga.js using the Referrers to Ignore list in the Google Analytics tag templates should now be configured from the Google Analytics Admin page.

Search Term Exclusions

Organic search terms can be excluded in Universal Analytics via the management interface. Learn how to exclude search terms (Help Center). Any search terms that you have previously configured Google Analytics to ignore using the Organic Keywords to Ignore list in the Google Analytics tag templates should now be configured from the Google Analytics Admin page.

Timeout Handling

Session and campaign timeouts can be set in Universal Analytics from the Google Analytics Admin page. Learn how to configure campaign and session timeout (Help Center). Any timeouts that you have previously configured using Session Cookie Timeout and Campaign Cookie Timeout settings in Google Analytics tag templates should now be configured from the Google Analytics Admin page.

Replacing the Basic Page View Tags

To enable basic page tracking with Universal Analytics in Google Tag Manager, follow these steps:

  • Create a new tag in your container
  • Name your tag (e.g. "Standard Pageview") and select Universal Analytics from the Tag Type dropdown
  • Enter your Google Analytics Tracking ID (UA-xxxxxx-xx) in the Tracking ID field. As a best practice, you can enter your Tracking ID in a Constant String Macro and use that macro in the Property ID field. This is especially helpful if you’ll be implementing other tag types (e.g. Events, Ecommerce, etc.) or are managing multiple Google Analytics properties.
  • Select Page View from the Track Type dropdown
  • (Optional) You may customize your Google Analytics tag further in the More Settings section of the tag editor. For more information about any of the configuration options, see the analytics.js Field Reference
  • Add a rule to fire the tag on all pages. If basic tracking is all you need, you’ll just add this single Google Analytics tag. However, if you track events or ecommerce transactions, you’ll need to add additional Google Analytics tags.

Replacing Other Tag Types

Beyond replacing your basic Page View tag, Google Tag Manager also supports the following Universal Analytics tag types:

  • Event – used to track a specific action or event, such as a button click.
  • Transaction – used to track an ecommerce transaction.
  • Virtual Pageviews – a variation on the standard page view tag. A page view tag fired in response to a specific user interaction.
  • Social – used to track social interactions with on-site social buttons and widgets.
  • Timing – used to track timing events on page, such as the load time of a resource.

The following sections will describe how to replace each of these tag types.

Best Practices for Creating Universal Analytics Tags

As you update to new Universal Analytics tags, it’s recommended that you use the same configuration settings for each tag in order to ensure the most consistent data in your reports. To make this easier, it is recommended that you:

  • Use Constant String macros for common settings as described above (e.g. for the Property ID and Auto Link Domains)
  • After configuring and saving your standard Page View tag, use this tag as a template for other tags by copying and adjusting the Track Type as necessary.

If you are migrating to Universal Analytics from an existing implementation of Google Analytics deployed via Google Tag Manager, you may choose to copy the existing tags in the manner described above, modifying the Tag Type, Track Type, and Settings as appropriate. Copying your existing tag instances in this manner will duplicate the tag rules that you have already configured.

Events

In Google Tag Manager, the Event Tracking Parameters for Universal Analytics Events should be very similar to those in older Google Analytics tag templates. If you are migrating to Universal Analytics from an existing implementation of Google Analytics deployed via Google Tag Manager, there should be no changes required beyond the configuration and deployment of the new tag instance.

For more details, see the Google Analytics (Universal Analytics) Tag Overview (Help Center) and the analytics.js Events Developer Guide.

Ecommerce Transactions

To deploy Universal Analytics Ecommerce Transaction tags in Google Tag Manger, your webmaster will need to push information about the transaction and component items to the data layer using the required Ecommerce data layer variables. This push should occur before the Google Tag Manager code snippet in your code.

If you are migrating to Universal Analytics from an existing implementation of Google Analytics deployed via Google Tag Manager, there should be no changes required for Ecommerce tracking beyond the configuration and deployment of the new tag instance.

For more details, see Google Analytics Ecommerce (Tag Manager Help Center).

Virtual Pageviews

To configure a Virtual Pageview in Google Tag Manager, you should create a new Universal Analytics tag with the Page View track type, and modify More Settings >> Basic Configuration >> Document Path with your desired Virtual Page Path (either with static text or using a macro). Then, update your firing rules to fire the tag in response to the user interaction event with which you want to associate the virtual pageview.

Social Interactions

In Google Tag Manager, the Social Tracking Parameters for Universal Analytics should be very similar to those in older Google Analytics tag templates. If you are migrating to Universal Analytics from an existing implementation of Google Analytics deployed via Google Tag Manager, there should be no changes required beyond the configuration and deployment of the new tag instance.

For more details, see the Google Analytics (Universal Analytics) Tag Manager Overview (Help Center) and the analytics.js Social Interactions Developer Guide.

User Timing

In Google Tag Manager, the Timing Tracking Parameters for Universal Analytics should be very similar to those in older Google Analytics tag templates. If you are migrating to Universal Analytics from an existing implementation of Google Analytics deployed via Google Tag Manager, there should be no changes required beyond the configuration and deployment of the new tag instance.

For more details, see the Google Analytics (Universal Analytics) Tag Manager article and the analytics.js User Timings Developer Guide.

Advanced Settings

The following sections describe how to use Google Tag Manager to implement advanced Google Analytics features.

Custom Variables

Custom variables have been replaced by custom dimensions in Universal Analytics. Although similar to custom variables, the name and scope of custom dimensions are configured via the Admin page, rather than in your code or in Google Tag Manager. Learn how to configure a custom dimension (Help Center).

The following example shows how to implement a custom dimension called Customer Type using Google Tag Manager:

To implement a Customer Type custom dimension, first sign into Google Analytics and create a custom dimension via the Google Analytics Admin page using the following values:

Name : Customer Type
Scope : User

When the custom dimension is created, it will be automatically assigned a numeric index. Make note of this index value, as it will be used later in this example.

Next, create a Data Layer Variable Macro that will hold the value of this Customer Type dimension using the following settings:

Macro NameMacro TypeData Layer Variable Name
Customer TypeData Layer VariablecustomerType

In your code, you can then push the Customer Type value into the data layer using the Data Layer Variable name configured in the macro:

dataLayer.push({
  'customerType': 'individual'
});

Lastly, while editing an existing Universal Analytics tag in Google Tag Manager, specify the value of the custom dimension in the More Settings >> Custom Dimensions section, using the numeric index of the custom dimension provided by Google Analytics, as well as the Customer Type Macro defined in the previous step.

Cross Domain Tracking

Google Tag Manager can automatically track user interactions using Universal Analytics tags across a source domain and destination domain in a single session using the Auto Link Domains setting.

To implement cross domain tracking, edit the Auto Link Domains field under More Settings >> Cross Domain Tracking. Google Tag Manager can automatically manage your cross domain tracking implementation when provided a comma-separated list of the domains across which you'd like to measure.

It is a best practice to specify the list of domains using a constant string macro, as in the following example:

Macro Name Macro Type Value
ga_domains Constant String Macro domain1.com,domain2.com,domain3.com

Specifying these settings enables the Auto Link plug-in for analytics.js to automatically implement cross domain tracking using the domains you've specified by tagging any links on the page pointing to those domains. Learn more about the Auto Link plug-in.

For advanced cross domain tracking use cases, including tracking across iframes, sending form data across domains, and more, see the analytics.js Cross Domain Developer Guide.

Working with Multiple Cookies

The following sections describe how to handle advanced migration scenarios when working with multiple sets of Google Analytics cookies:

Using Universal and Classic Google Analytics Tags on the same Website

Additional configuration may be required in cases where cookie information needs to be transferred from a Universal Analytics cookie to classic Google Analytics cookies, such as with larger websites that have not completely retagged with Universal Analytics tags and have both tracking codes present for some period of time:

Custom Cookie Names

If you are setting the cookie name of your Universal Tags to a custom value, you also must set that same cookie name value in your classic Google Analytics tag by using the uaName field in More Settings >> Fields to Set.

Custom Cookie Paths

If you are planning to use multiple Universal Analytics tags with different cookie domains and/or cookie paths, you must also update the uaDomain and/or class uaPath fields to use the same values in your classic Google Analytics tags via More Settings >> Fields to Set.

Custom Cookie Subdomains

If your website has multiple sets of visible Google Analytics cookies that were set by specifying the cookie path in classic Google Analytics tags, you can specify which set of cookies you would like migrated to your Universal Analytics tags by specifying the legacyCookiePath value while editing the tag in More Settings >> Fields to Set.

For example, if you had a set of cookies at the top level domain, example.com, as well as at the subdomain level, blog.example.com, you could choose to explicitly migrate the top-level domain cookies to Universal Analytics by setting the legacyCookiePath to example.com.