1

My question is for someone with experience using Google Analytics Linker Plugin programmatically. However my example has a bit complicated setup.

I'm currently working on the website which is using Google Tag Manager for loading GA scripts. It loads several GA scripts on the same page for different purposes.

This website also has a custom dropdown with related domains and I have to use GA Linker Plugin in order to keep them connected. I have to do it manually through the code on every domain element click event. I used the setup suggested by Google Analytics docs:

// inside onclick handler
ga(function(tracker) {
 var linkerParam = tracker.get('linkerParam');
 // apply to url and navigate window.location.href = url etc. 
});

Obviously this doesn't work in my case because of multiple trackers on the page:

// inside onclick handler
ga(function(tracker) {
 // tracker is undefined :( 
});

I managed to check how many trackers are available and requested linkerParam on each:

// inside onclick handler
ga(function () {
  var trackers = ga.getAll();
  trackers.forEach(function (tracker) {
    console.log(tracker.get('name'), tracker.get('trackingId'), tracker.get('linkerParam'));
  });
});

// outputs
// gtm1 UA-XXXYYY-1 _ga=2.234343242.904959305.3434234324-394093204.3094039402
// gtm2 UA-XXXYYY-2 _ga=2.234343242.904959305.3434234324-394093204.3094039402
// gtm3 UA-XXXYYY-3 _ga=2.234343242.904959305.3434234324-394093204.3094039402

As you can see all trackers have the same linker param value, but different names and tracking ids. My question are -

  1. Is it safe to use just first tracker from the list as long as all values are the same (e.g. ga.getAll()[0].get('linkerParam'))?

  2. Or will it be safer to create a specific name for one of the GA trackers in GTM and get it by name in code, e.g:

// inside onclick handler
ga(function () {
  var tracker = ga.getByName('websiteTracker');
  console.log(tracker.get('name'), tracker.get('trackingId'), tracker.get('linkerParam'));
});

// outputs
// gtm3 UA-XXXYYY-3 _ga=2.234343242.904959305.3434234324-394093204.3094039402

Thanks!

Kosmetika
  • 20,774
  • 37
  • 108
  • 172

1 Answers1

0

You might be overthinking the problem. Google Analytics through GTM has a simple, built-in way to implement cross-domain tracking. For each GA property that you are loading through GTM, simply set the domains you want to link in the "Cross-Domain Tracking" fields of the Analytics Setting variable or in the over-riding settings in the GA tag.

Bounteous has a very detailed article on how to implement and debug this here.

This has worked in almost all cases in which I want to implement cross-domain tracking through GTM - even if it is for numerous domains.

In the case that you actually need to do this programmatically, I'm pretty sure you can use the same linker param for all the GA properties. You can verify and debug your implementation by doing something like:

  1. Open up the real-time report in the GA property you want to test cross-domain tracking
  2. Visit domain1.com with these UTM values appended: domain1.com?utm_source=test&utm_medium=test
  3. You should be able to filter the real-time traffic by source / medium by clicking on "test" as source or medium under the traffic sources tab.
  4. Navigate to the content tab of the real-time report, you should see the page path and page title for domain1.com
  5. For each domain you want to test that cross-domain tracking works, click the link in your navigation
  6. If everything works, your filtered real-time view should update to the page path and title of domain2.com
  7. If cross-domain linking isn't working, the filtered real-time report will not update. Removing the filter, you should see "domain1.com / referral" or "(direct) / (none)" as the source / medium depending on your referral exclusions.

Hopefully this will help you configure cross-domain tracking or debug efficiently.