Tuesday, November 25, 2014

Tracking Multiple Subdomains in Universal Analytics

The new Universal Analytics has improved subdomain tracking ease out-of-the-box, no longer requiring the core tracking code to be modified to support multiple subdomains. The older ga.js tracking code would set cookies at the subdomain level, while the Universal Analytics tracking code sets cookies at the root domain level. This means that it doesn't matter what subdomain the the Universal Analytics tracking code runs on, the cookies will still be valid.


Just because Universal Analytics works out-of-the-box for subdomain tracking, doesn't mean it does what you need it to of course. Without any further setup, you won't be able to different subdomain traffic within your reports... you'll just see plain URIs like /contact-us and /learn-more. You won't be able to differentiate which subdomain that URI belonged to when the visitor loaded it. Further, you won't be able to report on subdomain traffic only without further setup.

The resolution of these short-falls is actually pretty easy.

First, make sure you have your basic Universal Analytics tracking code installed on every subdomain.

Next, your primary view needs custom filters setup:

  1. Go to Admin and select your primary view.
  2. Click Filters on the View column.
  3. Click +New filter
  4. Set the name as the full domain with subdomain (i.e. xyz.google.com)
  5. Set the Type to Custom
  6. Select Advanced as the subtype
  7. Set Field A -> Extract A to "Hostname" and "(xyz.google.com)" respectively
  8. Set Field B -> Extract B to "Request URI" and "(.*)" respectively
  9. Set Output To -> Constructor to "Request URI" and "$A1$B1" respectively
  10. Check Field A Required
  11. Uncheck Field B Required
  12. Check Override Output Field
  13. Uncheck Case Sensitive
  14. Save
This will track subdomain URLs separately from the primary domain URLs within your primary view. This will help differentiate traffic between your core domain and subdomains as well as between the subdomains themselves.



Finally, the new Views for the subdomains need to be setup:

  1. Go to Admin and click on the dropdown at the top of the View column
  2. Click Create New View
  3. Set the name of the view as the full domain (i.e xyz.google.com)
  4. Set the timezone as the same as your primary view (Eastern)
  5. Save this new view and click on Filters under the Admin > View column
  6. Click +New Filter
  7. Name it Subdomain Only
  8. Set the Type to Predefined and "Include Only" "traffic to the hostname" "that contain"
  9. Set the Hostname to the full subdomain (i.e. xyz.google.com)
  10. Save

This will add a new view tracking only the traffic on the subdomain.




No comments:

Post a Comment