Google标签管理器的递送属性

发布于 2025-02-05 17:07:25 字数 814 浏览 0 评论 0原文

我想为GTM标签设置defer属性,并且效果很好。但是,我的GTM包含另外10个脚本。 j.defer = true不影响这些脚本。如何将这些脚本属性作为defer而不是async? (可以参考此图像

gtm 的脚本

<script>
    (function (w, d, s, l, i) {
        w[l] = w[l] || []; w[l].push({
            'gtm.start':
                new Date().getTime(), event: 'gtm.js'
        });

        var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
        j.defer = true;
        j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
        f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'XXX-XXXXXXX');
</script>

I want to set the defer attribute for the GTM tag and it works well. But, my GTM contains another 10 scripts. The j.defer = true does not affect those scripts. How can I make those script attribute as defer instead of async? (can refer to this image)

Script for GTM

<script>
    (function (w, d, s, l, i) {
        w[l] = w[l] || []; w[l].push({
            'gtm.start':
                new Date().getTime(), event: 'gtm.js'
        });

        var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
        j.defer = true;
        j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
        f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'XXX-XXXXXXX');
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2025-02-12 17:07:25

GTM通过标签中的用户定义逻辑添加脚本。您可以访问您的GTM帐户,查找加载脚本的标签并对他们做完全相同的标签。但这是没有道理的,因为GTM已经推迟了,因此即使不明确推迟推迟,它添加到DOM中的任何脚本都会有效地推迟。

另一方面,除非您的GTM容器包含逻辑山,否则延迟应以任何可测量的方式与异步有所不同,但可能会损害GTM收集的数据。

说,如果页面加载更长,并且用户不想等待而退出,则由于GTM被推迟,因此您将不知道该弹跳的用户。我敢肯定,如果您使用DataLayer,或者GTM依赖于在页面加载之前可能会发射的其他事件侦听器,则事件计时中还有更多的边缘情况。

GTM adds scripts through user-defined logic in tags. You could get access to your GTM account, find tags that load scripts and do exactly the same to them. But it makes no sense since GTM is already deferred, so any scripts it adds to the DOM will effectively be deferred even if not explicitly deferred.

On the other hand, Unless your GTM container contains mountains of logic, defer should not differ from async in any measurable way, but it may harm the data that GTM collects.

Say, in case the page loads longer, and the user doesn't wanna wait and just quit, you will not know about that bounced user since GTM is deferred. I'm sure there are more edge cases in events timing in case you use datalayer or if GTM relies on other event listeners that could fire before the page is done loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文