Subdomain Tracking with Google Tag Manager & Universal Analytics

Posted in Search & Social

Subdomain tracking is easier than ever with Google Tag Manager and Universal Analytics - code customizations are now a thing of the past. You'll notice the for subdomains, the GTM configuration is almost exactly the same as for standard domains - *with the exception of some cookie settings. *

0: Set Up Your Views & Filters
Oooh, we have a step zero.

Before progressing with tag manager, we first need to make sure your Google Analytics account has correct views for your main domain and subdomain. This is controlled within your Google Analytics admin interface - NOT Tag Manager.

Go to my other blog post (Part B: THE PROFILES, Part C: THE FILTERS) that describes how to create views for subdomains vs main domains.

1. Create A Container & Install Code

This post also already assumes you've configured your basic Google Tag manager account and installed the exact same container code on the subdomain and main domain. But of you need an overview of how to do this, please see steps 1-5 of this post.

Note: *You do NOT need different, customized container code between your main domain and your subdomain. * Just plug in the same container code on all domains. (Isn't that nice and simple?)

After that you have the basic GTM installed, the next step is to create tags so you can start tracking data! Here's how:

2. Start Creating Your Universal Analytics Tag

Create a new tag and name it "Universal Analytics" (or really anything you want). Be sure to select "Universal Analytics" for the Tag Type:

new tag

Google Tag Manager-6

3. Add Your Tracking ID

This is assuming you use the same ID across all your main domain and subdomains (which we recommend!).

add your tracking id

4. Set The Cookie Domain

Under More Settings => Cookie Configuration, enter in whatever your domain is. Do not use a leading period, just yourdomain.com (not .yourdomain.com).

enter cookie domain

This will help reduce self-referrals from your main domain to your subdomain, and vice-versa.

5. Add A Rule to fire on "All Pages"

Don't forget that any tag is useless unless you tell Google Tag Manager which pages it goes on! Therefore, we'll add a rule that says Universal Analytics should fire on all pages.

The "All Pages" rule comes pre-configured in Google Analytics. Head on over to the "Firing Rules" section to add this to your Universal Analytics tag.

Add a rule to fire on all pages

After you select "Add", choose the rule "All Pages" and hit Save:

select rule

*6. SAVE! *
After you've saved the rules, next you wanna just save the tag itself. So hit save again (bottom of page).

7. Set up Preview & Debug

Before publishing changes, first you can preview everything to make sure it's working. Make sure you're in the "Overview" of your container draft, and click on "Preview":

preview tags

This will bring up a pop-up window. Go ahead and click on "debug":

debug version

The page will refresh, and display "You are now in preview & debug for the container draft".

8. Preview your Web Site

Next step is to visit your website and confirm that tags are firing. To go www.yourdomain.com, and sub.yourdomain.com, etc. If everything is correctly configured, you'll see an overlay from Google Tag Manager at the bottom of the page confirming that Google Universal Analytics is firing.

universal analytics fired on this page

9. Create a new Version

After you've confirmed your UA tags are firing, the next step is to save everything in a new version. Select Create Version:

create version

You can confirm that the latest version has been created, and check out the associated tags. (Depending on work you've done previously, this actual version number may vary):

inspect version

10. Publish the Version

Last step - hit Publish!

publish version

And that's it! You can now visit your main domain and subdomain views in Google Analytics, and head on over to "Real Time" to see your new code in action.

11. Addendum: Creating Rules for your Main Domain vs Subdomain

As you progress with creating other Universal Analytics tags, you may need tags to specifically fire on main domain pages, or subdomain pages. Luckily, Tag Manager allows you to set rules that control which pages tags fire on.

Rules are FLEXIBLE. There isn't just one way to approach this.

For example, you can create specific rules for a tag to fire on the subdomain:

fire on subdomain

(This tag fires when a URL matches a regular expression of sub.yourdomain.com. Notice the * at the end, which is a wild card that can match anything after the .com.) *

You can create a specific rule for a tag to fire on the main domain:

fire on main domain

(This tag fires when a URL matches a regular expression of www.yourdomain.com.)*

OR: You can just add specific rules alongside other rules you're creating. For example, let's say that your subdomain has PDF downloads that you want to track. So does the main domain, but for whatever reasons, you don't want to track those on the main domain.

You can either assign two rules to the PDF tag (one to fire on subdomain clicks only, one orders to fire only on PDF clicks) - OR, you can assign one rule to the PDF tag, that contains a stipulation for both PDF clicks and subdomain URLs.

Here's an example of a rule that covers both PDF clicks and subdomain URLs:

subdomain pdf clicks only

The configurations are endless. Experiment with this, and see which rules are easiest for you. Good luck!

More Search & Social