4

I have a web structure with a domain and a subdomain, let's call it example.com and blog.example.com. I want to be able to track both the main domain and it's subdirectory within the same Analytics profile so I've entered the same tracking code across example.com and blog.example.com

Tracking Codes:

This is the tracking code for the domain:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
  _gaq.push(['_trackPageview']);

  (function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

And here is the code for the subdomain:

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
 _gaq.push(['_setDomainName','example.com'],['_trackPageview']);

 (function () {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();

Issue

Notice I've used _gaq.push(['_setDomainName','example.com'],['_trackPageview']); for subdomain tracking. I see the post pages from the blog in the Analytics reports, but I can't distinguish between the homepage of the site and the homepage of the blog, they both appear in the reports in the same way (a slash /)

Question

Can anyone give me some insight on how to differentiate the homepage of the domain from the homepage of the subdirectory in GA reports?

3

To see the domain name along with the request path in the reports, create an advanced filter for your profile with the following settings:

  • Filter Type: Custom filter > Advanced
  • Field A: Hostname
  • Extract A: (.*)
  • Field B: Request URI
  • Extract B: (.*)
  • Output To: Request URI
  • Constructor: $A1$B1

enter image description here

You can also create a profile for each subdomain. For example for site1.com:

  1. New profile named site1.com
  2. In the new profile create a filter Include site1.com traffic only
  3. Filter type set as Custom filter and Include
  4. Filter field as Hostname
  5. Filter pattern as ^site1\.com$

Repeat for each domain. Data will only be collected once the profile is created.

(Google's explanation)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.