Written by Jose Vicente
On websites where content is available in multiple languages, it is common to use multiple domains to distribute content. We must keep in mind that, even if we use several domains to distribute the content of our website, the users of our site will navigate between them when changing the language with the selector, or when visiting our blog or the microsite of our latest product launched on a domain independent of the main one. In this case we are interested in counting this behavior as a single user, although in the analytics it is counted as a different visit as many times as the domain is changed.
The multi-domain architecture has special visitor tracking needs compared to sites stored in a single domain. Google Analytics considers visits to different domains as unique and unrelated, it is not interested in having visitor data from one website appear in the Analytics report of another website without any relation to the first.
How to set up Analytics multi-domain tracking
Since we are going to use all our domains as a single site, the first thing we must be clear about is that we are going to use a single account to group all the data of the visits of our multidomain site.
Although the standard Google Analytics configuration is intended to track content and users from a single domain per account, we can customize it for a multi-domain configuration like the one in the scenario in the following example.
Tracking code for mydomain.com:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'midominio.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
Tracking code for mydomain.com:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'midominio.es]);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
Tracking code for mydomain.fr:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'midominio.fr]);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
As can be seen in the tracking codes, in addition to the standard commands _setAccount
and _trackPageview
to record the visit we add two lines between them:
_setDomainName
with the name of the domain where the tracking code is located._setAllowLinker
with valuetrue
to allow data to pass between the top-level domains.
How to set up cross links between domains
In addition to including the _setDomainName()
and _setAllowLinker()
functions in the tracking code, we must use the _link()
function in the links to keep Google Analytics cookie data between our domains using the HTTP GET method. To implement this, we only have to include the function _link()
in the onlick event of the links that exist between our domains.
For example, if we have the link <a href="”http://www.midominio.es”">Castellano</a>
at www.midominio.com, we add the function link() <a onclick="”_gaq.push([‘_link’,’http://www.midominio.es’]);" href="”http://www.midominio.es”">Castellano</a>
.
Google Analytics tracking cookies are used to:
- Determine to which domain to attribute the visit
- Distinguish unique users
- Remember number and time since previous visit
- Remembering the traffic source and its related information
- Determines the start and end of the browsing session
- Remembering the value of custom variables
Google Analytics’ way of passing this data from one domain to another is through the HTTP GET method, so we will see that the _link()
function adds the following parameters in the link destination URL:
__utma
used to distinguish users and sessions__utmb
used to determine a new session or visit__utmc
is not used for the standard ga.js code, but to operate with urchin.js.__utmz
stores the traffic source or campaign through which the user has reached our site.__utmv
used to store custom variables, this cookie is created when you use the function_setCustomVar
In addition to passing all this data, the _link()
function will take care of changing the document.location
and redirect the user to the destination URL of the link.
This system is totally transparent to search engines since the Google robot will always follow the link included in the href of the link, but the user will execute the onclick when using the link. Therefore, we should not worry about the inclusion of the parameters when browsing our site, since they are not included in the href and are added via JavaScript, they will not be tracked.
Setting up Analytics to track multiple domains
When analyzing the data in Analytics, we will encounter the problem that we will not be able to distinguish which page corresponds to each of our domains (unless we cross the page dimension with the host dimension), so it is highly recommended to configure at least the following traffic profiles with their corresponding filters:
- A profile for each of the domains: in this way we will be able to analyze the traffic separately for each of the domains of our site. We will therefore configure a filter for each of them to allow only traffic from the domain of each profile.
- A global profile for our entire website in which, by means of an advanced filter, we will add the host name to the page name in order to differentiate them during data analysis
- The default profile: this profile is already created since the account was created, when we create other profiles with filters we must keep it for security reasons.
With this Analytics profile configuration we ensure that a user will be treated as a single user even if they browse between domains on our multi-domain website and that we will be able to analyze each of the domains separately.