Cross domain tracking

Cross domain tracking means that you will be able to link several userIDs, which are domain specific, to each other. Harvest Collect supports cross domain tracking.

How does it work?

Step 1 - Configure domains

The first step is that you need to define the domains that are related to your account. Whenever you link from one domain to the other, you will be able to add the harvest_user_id parameter to the url. Harvest Collect will only process this parameter properly when the link originated from a domain that was configured in the account.

Step 2 - Tag all your links

The second step is that you will have to set the harvest_user_id parameter to all of the links from one domain to the other. Currently, this is not yet built in in Harvest, but you could use the example code below.

document.addEventListener("harvest-and-dom-ready", function () {

    //Define the partner domains
    var partnerDomains = [
        "example.com"
    ];

    //Retrieve all links
    var links = document.querySelectorAll("a");

    //Loop through all links
    for(var i=0; i<links.length; i++){
        (function(number){

            //Cache link and href
            var currentLink = links[number];
            var currentHref = currentLink.href;

            //Only if the link has a href, proceed
            if(currentHref) {

                //Loop through all partner domains
                for(var j=0; j<partnerDomains.length; j++){

                    //Check if the href contains the url of a partner domain
                    if(currentHref.indexOf(partnerDomains) > -1){

                        //Check if there already is a ? in the url

                        var userID = harvest.getUserID();
                        if(currentHref.indexOf("?") > -1) {
                            links[number].href = currentHref + "&harvest_user_id=" + userID;
                        } else {
                            links[number].href = currentHref + "?harvest_user_id=" + userID;
                        }
                    }
                }
            }
        })(i)
    }

});

The code above showcases some interesting helper functions.

An example of the final url is:

Step 3 - Receive the userID

Whenever a user tracks a pageview on a page where the url is tagged with harvest_user_id, Harvest Collect will process the parameter.

The parameter will only be added to userData.crossUserIDs when the referring domain is a domain that is configured in the Harvest Console.

You will notice that when you meet the conditions 1) a tagged url and 2) a referrer that is configured in your domains, that a new variable in userData will emerge.

userData.crossUserIDs

This variable will hold a list of all userIDs that are linked due to cross domain tracking. It will make it possible to link all userIDs together.