How To Set Up And View Subdomain Tracking In Google Analytics


If you have not created a Google Analytics account, click here to learn how to do so.

PREFACE

You've got two domain names, www.example.com and shop.example.com, and you'd like to have your Google Analytics account track both of them. Not a problem! Let's go ahead and get started.

ADDING GOOGLE ANALYTICS TO YOUR SITE

The Google Analytics script must be added in all of the websites you want to track in order for this tutorial to work.

  • Log in to your Google Analytics account if you haven't done so already.
  • Click on Admin in the bottom left-hand corner within the panel.
  • In the second column, Property, click on Tracking Info.
  • Click on Tracking Code within the dropdown menu.
  • Copy the information within the Global Site Tag (gtag.js) text box.
  • Paste the code you just copied within the section of your website.

SET UP AND VIEW SUBDOMAIN TRACKING

  • Log in to your Google Analytics account if you haven't done so already.
  • Click on Admin in the bottom left-hand corner within the panel.
  • Click on Filters in that last column, View.
  • Click on the red + Add Filter button.
  • Add Filter to View
    • Filter Name: Give your filter a name.
    • Filter Type: Custom.
      • Choose the Advanced option.
      • Field A -> Extract A: Choose Hostname in the dropdown menu and type in (.*).
      • Field B -> Extract B: Choose Request URI in the dropdown menu and type in (.*).
      • Output To ->: Choose Request URI in the dropdown menu and type in $A1$B1.
      • Field A and Override Output Field are the only checkboxes that should be checked.
  • Click Save.
  • Go back into the admin panel screen (the one with the three-column display).
  • Click on Tracking Info
  • Click on Referral Exclusion List within the dropdown menu.
  • You're main site should be listed as the first option, if not, then click on + Add Referral Exclusion.
  • Type in the basic domain name. Example: example.com. No need to include the "www" or the subdomain name.
  • Click Create.
  • In the left-hand panel, click on the house-looking icon to get taken back to the main Google Analytics dashboard.
  • Click on Real-Time.
  • Click on Overview.

This will give you a real-time view of who is on your site.

LET'S TEST IT OUT

  • Open up a new tab.
  • Visit your website.
  • Go back to your Google Analytics tab and watch as it displays the amount of active users that are currently on your site and how they are accessing it.
  • Leave this tab open and go to your subdomain site on your phone.
  • It might take a minute, but Google Analytics should update itself and display another active user and how they are accessing it as well.

THE END