Google analytics on one site with different domains - google-analytics

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

Related

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?)

Tracking subdomain with 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.

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.

Tracking Multiple Domains with Google Analytics in same code

I have portal which behaves like multiple portal.
The portal code base is same but for all sites but content is based on which url or domain you came across.
Currently i am able to track my domain
example.com
and also subdomains like
a.example.com, b.example.com
. But i want to also track
anotherexample.com
which also point to same domain. How can I do?
Any suggestions?
multiple url pointed to same code base. It does not matter. The only matter is the url above and the tracking code in site is matching or not. So you have to take google access code from database which just write in address bar.
Codes:
<!-- Google Analytics -->
<script type="text/javascript">
var accountNameFromDB = ...Some Operations...
var domainNameFromDB = ...Some Operations...
var _gaq = _gaq || [];
_gaq.push(['_setAccount', accountNameFromDB]);
_gaq.push(['_setDomainName', domainNameFromDB]);
_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>
Just take accountNameFromDB and domainNameFromDB variables dynmically.
Add this code head of master page(or main template) or add every page.

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