title: Get Google Analytics Linker params with multiple trackers on the page
body: <p>My question is for someone with experience using <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/linker" rel="nofollow noreferrer">Google Analytics Linker Plugin</a> programmatically. However my example has a bit complicated setup.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>// inside onclick handler
  ga(function(tracker) {
   var linkerParam = tracker.get('linkerParam');
   // apply to url and navigate window.location.href = url etc. 
  });
  </code></pre>
  
  <p>Obviously this doesn't work in my case because of multiple trackers on the page:</p>
  
  <pre><code>// inside onclick handler
  ga(function(tracker) {
   // tracker is undefined :( 
  });
  </code></pre>
  
  <p>I managed to check how many trackers are available and requested <code>linkerParam</code> on each:</p>
  
  <pre><code>// 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
  </code></pre>
  
  <p>As you can see all trackers have the same linker param value, but different names and tracking ids. My question are - </p>
  
  <ol>
  <li><p><strong>Is it safe to use just first tracker from the list as long as all values are the same (e.g. <code>ga.getAll()[0].get('linkerParam')</code>)?</strong></p></li>
  <li><p><strong>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:</strong></p></li>
  </ol>
  
  <pre><code>// 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
  </code></pre>
  
  <p>Thanks!</p>