如果您在google tagmanager代码段中填充了数据层,会发生什么?

时间:2017-05-09 18:49:04

标签: google-analytics google-tag-manager

客户端具有以下GTM代码段的实现。到目前为止,我只看到了在加载GTM代码段之前使用数据层推送填充数据层的实现。有没有一个很好的论据来实现这样的GTM片段?

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=xxxxxxxx" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>
    dataLayer = [{"automaticLogin":"true","loginSuccess":true,"pageName":"homepage","pagetype":"home","customerBaskedValue":xxxxx,"customerId":"xxxxxxx","sitePage":"d","isOptIn":true,"sessionId":"xxxxxxxxx","customerGender":"man","customerBirthDate":"1989-09-21T00:00:00","customerZip":"xxxxx","customerCity":"xxxxx","customerState":"Nederland","customerEmailID":"xxxx","orderNewCustomer":false,"customerLastMarketingChannel":null,"sessionDevice":"desktop","isFirstVisit":false}];

    (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.async = true; j.src = '//www.googletagmanager.com/gtm.js?id=' + i + dl;
        f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'GTM-xxxx');
</script>
<!-- End Google Tag Manager -->

1 个答案:

答案 0 :(得分:2)

这绝对是好的,有时也会受到鼓励。在容器代码执行之前将事物推送到dataLayer的好处是,一旦gtm.js事件被触发,这些值将可供GTM使用。 gtm.js事件通常用作触发器(例如,在内置的所有页面触发器中)。因此,当您希望将某些值传递给标签时,为其分配了All Pages触发器,您必须确保在容器代码执行之前将值推送到dataLayer