新的gtag谷歌分析手动添加url _gl



我正试图将_gl的值添加到URL中,以便跨域应用。

目前,我尝试了以下选项:

const decorateUrl = (urlString: string) => {
var ga = window.dataLayer;
var tracker;
if (ga && typeof ga.getAll === 'function') {
tracker = ga.getAll()[0]; // Uses the first tracker created on the page
urlString = (new window.gaplugins.Linker(tracker)).decorate(urlString);
}

return urlString;
}

const decorateURL = (url: string) => {
let destinationLink = false;
var ga = window[window['GoogleAnalyticsObject']];
console.log(ga,'ga test decorate')
if (ga) {
let tracker = ga.getAll()[0];
let linker = new window.gaplugins.Linker(tracker);
destinationLink = linker.decorate(url);
}
return (destinationLink ? url + '?' + destinationLink : url);
}

但是这些都没有将_gl代码设置为URL。

我在标题中注入这个代码

let gtagLinkScript = destinationWindow.document.createElement("script");
gtagLinkScript.setAttribute('async', 'true');
gtagLinkScript.setAttribute('src', `https://www.googletagmanager.com/gtag/js?id=${ trackingID }`);

let gtagAnotherScript = destinationWindow.document.createElement("script");
gtagAnotherScript.innerText = `gtag('set', 'linker', {'domains': ['${crossDomain}']});gtag('config', '${ trackingID }');`;

有人能帮忙吗?

在GA4属性中,建议通过url传递client_id和session_id:https://support.google.com/analytics/answer/10071811?hl=en#zippy=%2Cmanual-设置

相关内容

  • 没有找到相关文章

最新更新