Google Analytics on Subdomain

12,044

According to Google's analytics help, specifying the root domain in the way you have will allow you to track stats on subdomains. So no, it doesn't seem like you need to do anything special.

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#domainSubDomains

Share:
12,044

Related videos on Youtube

user3137996
Author by

user3137996

Updated on June 04, 2022

Comments

  • user3137996
    user3137996 almost 2 years

    I just generated the tracking code for a new Google Analytics account, and the domain I want to track is actually a subdomain. When setting up the account, I entered the subdomain as the URL I wanted to track, but I noticed when the tracking code was generated, it referenced the main domain and not the subdomain I had entered. Please see below, and please note that in the code below, I replaced the actual domain with "example.com". So, I have two questions related to this

    1. I plan to insert this tracking code on my subdomain, but do I need to do anything special in the analytics settings to ensure that I only see stats for my subdomain and not the main domain? I don't have control over the main domain, and they don't have analytics installed on it.

    2. If the person in charge of the main domain decides to install analytics on the main site, will my code affect his account in any way being that my tracking code references the main domain instead of my subdomain?

    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-46251874-1', 'example.com');
    ga('send', 'pageview');
    </script>
    
  • user3137996
    user3137996 over 10 years
    Awesome! Thanks so much for your response. This resource is very helpful, and it's good to hear I don't have to do anything special to get Analytics set up on this subdomain. Thank you for your help!!!!!!!!
  • Ben
    Ben over 10 years
    @user3137996 - You should mark me as the correct answer if this is the correct answer. It helps build other's confidence when they find this on Google.
  • user3137996
    user3137996 over 10 years
    I'm sorry. I'm new to Stackoverflow, and don't even see how to mark this as the correct answer. I would love to though if you tell me how. Thank you again!
  • user1301428
    user1301428 about 9 years
    Yeah but come on, the answer is still not marked as accepted. People in charge of configuring Google Analytics and yet they cannot see how to mark a question as accepted. Things I will never understand.
  • Athlan
    Athlan over 8 years
    This documentation is depracated.
  • Abram
    Abram about 7 years
    Yes, this is the legacy code base. We need a modern answer.