首页 > 解决方案 > 跨域的 gtag 链接器

问题描述

我正在尝试使用新 gtag 在 URL 中设置链接,但在 URL 中看不到链接的代码。

我这样设置谷歌分析:

gaScript.setAttribute('async', 'true');
gaScript.setAttribute('src', `https://www.googletagmanager.com/gtag/js?id=${ trackingID }`);
and
gaScript2.innerText = `window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag(\'js\', new Date());gtag(\'config\', \'${ trackingID }\', {\'linker\': {'domains': [\'${crossDomain}\']}});`;

嗨有这个:

const decorateURL = (url: string) => {
    let destinationLink = false;
    if (ga) {
       let tracker = ga.getAll()[0];
       let linker = new window.gaplugins.Linker(tracker);
       destinationLink = linker.decorate(url);
    }

    return (destinationLink ? url + '?' + destinationLink : url);
}

和电话:

window.location.assign(decorateURL(data.redirectUrl));

目前, o 收到一条错误消息:

Uncaught ReferenceError: ga is not defined

有人可以帮忙用 gtag 定义网址吗?提前致谢

标签: google-people-apigtag.js

解决方案


推荐阅读