Michael Spencer
Michael Spencer

Reputation: 47

Google Analytics gtag.js Manually adding the linker cross-domain parameter to URLs

For the gtag.js implementation of Google Analytics wanting to manually add the linker parameter to specific URLs so that the _ga parameter is present on the clicked URL however it seems that the documentation at https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain doesn't currently detail the manual method unless I've misunderstood the document? Can anyone help?

Upvotes: 2

Views: 2004

Answers (2)

vir us
vir us

Reputation: 10715

after gtag is inited you can do it like this:

gtag('config', analyticsId, ...)
...

var tracker = ga.getAll()[0];
var linker = new window.gaplugins.Linker(tracker);
var destinationLink = linker.decorate(myLinkToDecorate);

ga is the analytics instance created by gtag

Upvotes: 2

Дмитро Булах
Дмитро Булах

Reputation: 3847

the easiest trick to do that would be to initiate the dummy analytics.js tracker ( with only ga('create'..) command and no ga('send'...)) with linker plugin enabled and then utilize the linker:decorate command over the selected links. Details are described here https://developers.google.com/analytics/devguides/collection/analyticsjs/linker#manually_adding_linker_parameters

Upvotes: 0

Related Questions