Tracking subdomain with Google Analytics - google-analytics

I have been tracking both the main site and the subdomain using the main site's code, however, when I go to Site Content > Pages, it links to the main domain when it's supposed to link to the subdomain for viewed pages that are supposed to refer to the subdomain.
This is the code I have:
Main site:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxx']);
_gaq.push(['_setDomainName', 'sitename.com']);
_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);
})();
Subdomain:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxx']);
_gaq.push(['_setDomainName', 'sub.sitename.com']);
_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);
})();
I have read Google Analytics' documentation on the subdomain. For _setDomainName I have tried both .sitename.com and sitename.com, but it still shows the same results. So, the page content in the Google Analytics dashboard links to the main site, but it won't link to the subdomain when referring to subdomain pages.
This poses a problem for index pages because how will I know the division of unique views between the domain and subdomain? I must be doing something wrong here!

Have you considered setting up separate profiles for your subdomains? Example:
profile 1: rollup that has no filters, takes everything, so that you can see data from everywhere
profile 2: only traffic for www.sitename.com. Create a filter to include only www.sitename.com traffic.
profile 3: only traffic for sub.sitename.com. Create a filter to include only sub.sitename.com traffic.

Related

Google analytics on one site with different domains

We how a site that is accessible from two different domains. let it be original.com and new.com
We have such sript
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-*******-**']);
_gaq.push(['_setDomainName', 'original.com']);
_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>
The problem is that in GA I see sessions from origina.com but I don't see sessions from new.com
How should I modify code above to be able to see sessions from both domains in one Google Analytics View?
UPDATE
Both domains has points to one app by main damain and to another app by subdomain. So original.com and new.com point to one app and sub.original.com and sub.new.com point to another app.
I need to see both original.com and new.com in one view and sub.original.com and sub.new.com in another view

google analytics setup, not tracking

I'm trying to implement google analytics on a page but it refuses to track anything.
the public domain is on www.publicdomain.com, when entering the page its redirected to: www.publicdomain.com/sub1/sub2/index.php
this website is hosted on another domain:
www.privatedomain.com/publicdomain/sub1/sub2/index.php
This is the GA code I'm using inside the body tag of the index.php file:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9999999-9']);
_gaq.push(['_setDomainName', 'publicdomain.com']);
_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>
Any ideas of what could be wrong?
Here are some things to check:
Are you using the correct UA number? (i.e. not 999999-99)
Are the GA cookies being created? (__utm[abcz])
Is the __utm.gif request being sent back to Google? If not, is your browser blocking it? (i.e. is Do Not Track enabled?)

How can I tell that my Google Analytics cross domain code is working

I am implementing Google Analytics for a customer that has part of their site on a subdomain on another SSL encrypted site. For example, let's say that their URL is http://www.first-site.com and they have a contact form located at https:// www.second-site.com/first-site/. Also, several other sites that run Google Analytics have part of their site on different subdomains of www.second-site.com.
(Current code for both pages in both domains is listed below)
The Analytics is running and it is tracking both domains and the cookie information is being passed in the URL from one domain to the other, however when I look at the cookie, the visitor ID changes when I go from one to the other. Is this supposed to happen?
Also, the Real Time Analytics report shows a new visitor when I go from one domain to the other. Does this mean that the cross domain code isn't working? I thought that the visitorID in the cookie would be the same from domain to domain.
Any help would be greatly appreciated and any tips for testing the cross domain analytics would be appreciated, too.
Tracking code for http://www.first-site.com: (actual UA number has been replaced)
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_setDomainName', 'first-site.com']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
(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>
Code for https:// www.second-site.com/first-site/ :
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_setCookiePath', '/first-site/']);
_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>
Here is an example URL from a linked page: https:// www.second-site.com/first-site/apply.htm?_utma=226662157.1705427553.1330793721.1330793721.1330802012.2&_utmb=226662157.1.10.1330802012&_utmc=226662157&_utmx=-&_utmz=226662157.1330793721.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)&_utmv=-&__utmk=195995183
You need _gaq.push(['_setAllowLinker', true]) on the second site as well.
Also make sure that the _trackPageview comes after all other calls.
If you do that you should start to see the visitor the visitorId being the same.
Also note that not all __utma cookie needs to be the same. You just need to check the second number after the first dot. If that is the same than it's probably working. The __utmz cookie also should have the same referrals.
Note that you don't need _setAllowHash anymore. It's deprecated now. And you probably don't need _setCookiePath, unless you have a very good reason to that, and the only good reason is if you have other cookies on second domain that you want to isolate.

Google Analytics (asynchronous) on a large site with pages containing iframes

I want to track a large website as a whole with several 'normal'pages and several pages containing i-frames. The framed pages' sources are at different domains.
How would I go about in making it work in such a way that all the pages (including the i-framed pages) are tracked in the correct way, even allowing in-page analytics on them?
Here's how far I got: Your comments, please?
1 normal pages should have the normal tracking code.
2 The pages containing i-frames AND the framed pages inside the i-frame should have the adjusted multi-domain tracking code:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-xx']);
_gaq.push(['_setDomainName', '.THIS_IS_THE_SUBPAGE_URL_CONTAINING_I-FRAME']);
_gaq.push(['_trackPageview']);
_gaq.push(function() {
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('THIS_IS_THE_I-FRAME_ID');
iframe.src = pageTracker._getLinkerUrl('THIS_IS_THE_FRAMED_PAGE_URL');
});
(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);
})();
Question:
Am I going about this in the right way? Do the frames need some sort of Javascript cookie transfer? What about P3P policy, does this need to be added?

How do I track 2 domains which point to the same host. 2nd domain points to a sub directory of the 1st site

This is my exact setup. I have a single web host. I have assigned a primary dns to that host. for instance www.primary.com points to the host. THe host allows 'addon domains'. An addon domain is in effect a subdirectory of the host, is accessible via www.secondary.com OR secondary.primary.com. I can ALSO access the content at www.secondary.com by typing in www.primary.com/secondary.com
I want to track each domain as a totally separate website, with no overlap in the visitors. (the sites for all intents and purpose are two completely separate site with nothing really linking the two)
I am absolutely confused as to what code to use where and how to customize it. So any and all help would be appreciated.
Thanks in advance
Either you use two different profiles with unique profile ID to track them (e.g. UA-123456789-1 for the www.primary.com and UA-123456789-2 for the www.secondary.com) and make sure each site only has one of the codes, or you can use filters based on domain/sub-domain/directory structure to do this (or to support it).
I would go with separate tracking codes, as it is by far the easier choice.
Example:
Site 1:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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>
Site 2:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_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>
Be sure to create the profile for both.

Resources