Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics on Subdomain

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>
like image 371
user3137996 Avatar asked Dec 30 '13 18:12

user3137996


1 Answers

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

like image 166
Webnet Avatar answered Sep 27 '22 16:09

Webnet