Google cross domain tracking – how to get the linker parameter

I had to tackle an interesting problem few weeks ago. We were passing our traffic form one domain to another but suddnly we noticeed all our traffic data in Google Analytics is not making any sense anymore..!

The problem was the linker parameter was not getting passed at the end of the URL.

Linker parameter looks something like this

_ga=1.199239214.1624002396.1440697407

This is how it should work

Let’s say you are going from domain A to domain B

When you click a link anywhere in site A which leads to site B

at the time of clicking Google Javascripts get the linker parameter and append it to the end of the Url.

eg

http://b.com/yourdestination?_ga=1.199239214.1624002396.1440697407

But this was not happening because we were using JQuery “preventDefault” method in our JS code.

Our solution for this was to retrieve the linker parameter manually and appending it at the end of the links manually (this was not happening because we were using jQuery “preventDefault” on those clicks).

Below is the script I used to get the linker parameter.

 

function getLinkerParam() {
 /*
 This function get the linker parameter
 This is used for cross domain tracking
 -- Cross domain tracking does not work automatically when you redirect the user using JS thefore we are passing the tracking ID manually
 */
 var linkerParam;
 try {
  if (typeof ga != 'undefined') {
   // live property ID
   var propertyID = 'UA-65170725-1';
   var targetTracker;
   var trackers = ga.getAll();
   for (var i = 0; i & lt; trackers.length; i++) {
    // tracker is not null and has get function
    if (trackers[i] & amp; & amp; typeof trackers[i].get != 'undefined') {
     // tracker property ID matches live property ID
     if (trackers[i].get('trackingId') == propertyID) {
      // set as target tracker
      targetTracker = trackers[i];
     }
    }
   }
   if (targetTracker) {
    // get linker paramater for url;
    linkerParam = targetTracker.get('linkerParam');
   }
  } else {
   // ga not defined
  }
 } catch (e) {
  // script error
 }
 return linkerParam;
}

Special thanks goes to Mr. Max Yodgee for sharing this code with me.
You can see their website site here.

One Response to “Google cross domain tracking – how to get the linker parameter”

  1. Jan Zac says:

    Hello ,

    I saw your tweets and thought I will check your website. Have to say it looks very good!
    I’m also interested in this topic and have recently started my journey as young entrepreneur.

    I’m also looking for the ways on how to promote my website. I have tried AdSense and Facebok Ads, however it is getting very expensive.
    Can you recommend something what works best for you?

    Would appreciate, if you can have a quick look at my website and give me an advice what I should improve: http://janzac.com/
    (Recently I have added a new page about FutureNet and the way how users can make money on this social networking portal.)

    I wanted to subscribe to your newsletter, but I couldn’t find it. Do you have it?

    Hope to hear from you soon.

    P.S.
    Maybe I will add link to your website on my website and you will add link to my website on your website? It will improve SEO of our websites, right? What do you think?

    Regards
    Jan Zac