'无法字符串化dataLayer'当使用谷歌标签管理器'点击监听器'在angular j

'Cannot stringify dataLayer' when using Google Tag Managers 'click-listener' in angular-js app

本文关键字:管理器 angular 标签 监听器 字符串 dataLayer 谷歌      更新时间:2023-09-26

我们正试图通过angularjs应用程序的谷歌标签管理器实现跟踪。当使用标签管理器中定义的点击监听器时,每次点击(或者看起来是这样)都会将以下脚本注入应用程序:

(function (a)
{
    var b = {}, c;
    for (c in a || {})if (a.hasOwnProperty(c) && "undefined" != typeof a[c])try {
        b[c] = JSON.stringify(a[c])
    } catch (d) {
        console.log("Cannot stringify " + c)
    }
    a = document.createEvent("CustomEvent");
    a.initCustomEvent("RetrievedVariablesEvent", !0, !0, {variables: b});
    window.dispatchEvent(a)
})({'studioV2': window['studioV2'], 'richMediaIframeBreakoutCreatives': window['richMediaIframeBreakoutCreatives'], 'dataLayer': window['dataLayer']})

当跟踪点击时,会出现"Cannot stringify dataLayer"错误。原因是,通过单击,元素也被发送,它对自己有一个循环引用,因为子引用和父引用附加到对象(可能通过jquery??)。

有什么想法可以用谷歌标签管理器实现点击监听器,而不会遇到这种递归?

原来原因是Chrome扩展标记助手。卸载后,通知以及另一个错误都消失了。