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: first.ru and second.ru. If the user gets to the first.ru site first, and then follows the link from him to the second.ru website and places an order on it, then the return path to the goal without using cross-domain tracking will look like this:

    image

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

    image

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

    image

    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:

    pageTracker._setDomainName("none");
    pageTracker._setAllowLinker(true);
    pageTracker._setAllowHash(false);







    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 site1.ru and site2.ru sites and their subdomains poddomen.site1.ru and poddomen.site2.ru.

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

    For site1.ru and its subdomains: For site2.ru and its subdomains:
    pageTracker._setDomainName(".site1.ru");
    pageTracker._setAllowLinker(true);
    pageTracker._setAllowHash(false);



    pageTracker._setDomainName(".site2.ru");
    pageTracker._setAllowLinker(true);
    pageTracker._setAllowHash(false);


    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.

    Example:

    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 site1.ru/news and site2.ru/news will be displayed as / news. In order to add a domain to the pages (instead of / news there will already be site1.ru/news and site2.ru/news), 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:

    image

    we get the following:

    image

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

    Also popular now: