Cross Domain Tracking with Google Analytics

    What is cross-domain tracking and why is it needed?

    imageThe essence of cross-domain tracking using the Google Analytics web analytics system is to transfer information from the cookies of the previous site when switching from one site to another through a link or form, as a result of which the user’s session would not break off, but would allow tracking the user's movements across multiple monitored sites.

    In fact, it turns out that the visitor does not leave the site via an external link, but simply goes to another page, although in reality he is already on another domain. Thus, we can trace the user's path from the beginning to the end of his visits to a group of sites.

    Another important result of this implementation for commercial sites is the ability to track the initial source, leading, for example, to ordering goods on the site.

    In Google Analytics, there is a section called “Return to the Goal”, with which we can track the visitor’s path before making an order.

    Here's how to use it in practice.

    For example, a company has 2 sites: and If the user gets to the site first, and then follows the link from him to the website and places an order on it, then the return path to the goal without using cross-domain tracking will look like this:


    When using cross-domain tracking in reports, we can detect the initial source of this visit:


    In addition to this, we can also find out the keyword by which the visitor first came to the site, subsequently ordering goods on


    All this extends the data collection capabilities of Google Analytics, which allows for a deeper analysis of sites.

    Cross Domain Tracking Implementation

    To implement this tracking, do the following:
    1. Make some changes to the Google Analytics tracking code for each domain
    2. Adding onClick and onSubmit events to outgoing links and / or forms
    3. Add filter to Google Analytics web analytics site profile

    1. Changes to the Google Analytics tracking code

    In order to track general statistics for all domains in one profile, you should create a new profile and for all domains in the Google Analytics code write the same ID, i.e. UA-XXXXX-X With this option of collecting information, statistics for all sites will be collected and stored in one profile.

    As a result, we will be able to collect statistics and simultaneously observe from which page of the other website we are tracking, the user went to, by which way he got to this page of the website, etc.

    Next, you will need to include the following lines of code in the standard Google Analytics tracking code for each site: Using an example of real code, it will look like this:


    By adding these lines of code, we activate the methods of the Google Analytics system to enable the transfer of user cookies (saving cookies from visiting the previous site, instead of creating new ones) from one domain to another.

    In some cases, in addition to the domains themselves, we need to consider their subdomains as well.

    Suppose we have and sites and their subdomains and

    In this case, the Google Analytics code on these two sites and subdomains will look like this:

    For and its subdomains: For and its subdomains:


    2. Adding onClick and onSubmit events to outgoing links and forms

    The next step is to add the _link method to all outgoing links leading to the required domains.


    need to replace the link
    Link to an external site

    to the link
    Link to an external site

    Thus, the same onClick event is added to all external links.

    Now, when switching to the second website we are monitoring, the user's cookies will not be created again, but will be transferred from the previous domain, and for this site the visitor will not be considered new by Google Analytics: it will have its own history (where did it come from, for what keywords, what looked at the previous site and so on). As a result, it turns out that the visitor simply moved to another section of the site.

    If the information is transferred between domains using forms, you must use the _linkByPost method .

    Usage example:

    3. Adding a filter to the site profile

    By default, all site data is collected in one profile; accordingly, only site pages (without domains) will be displayed in Google Analytics reports. For example, the pages of two domains and will be displayed as / news. In order to add a domain to the pages (instead of / news there will already be and, you need to create the following filter in your profile: Filter

    type: User filter> Advanced
    Field A: Host name
    Extract A: ( . *)
    Field B: Request URI
    Extract B: (. ​​*)
    Output to: Request URI
    Constructor: / $ A1 $ B1

    As a result, instead of the following entries in the Google Analytics reports:


    we get the following:


    As a result of the work, we get a working tool for tracking groups of sites.

    Also popular now: