0
votes

I've been asked to setup some dataLayer pushes for google tag manager for our external client.

I've setup the GTM script

    <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.async = true;
    j.src =
        'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
    f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'XXXXXX');</script>

and have added a dataLayer push event

{% macro billing_tracking(page, shopper_session) %}
<script>
    window.dataLayer = window.dataLayer || []
    window.dataLayer.push({
        'users_state': '',
        'status': '',
        'card_value': {{ shopper_session.amount | format_2dp | tojson}},
        'order_id': '',
        'virtual_page': {{ page|tojson }},
        'event': 'Virtual Page',
    })
</script>
{% endmacro %}

I then load this macro in my HTML page.

I am expecting to see a post request made when this dataLayer.push event is loaded. That doesn't seem to happen. Is that a correct assumption? I do see a get event gtm.js?id=id but I would expect to see the post event being fired back to google tag manager?

Any ideas why this isn't happening?

1

1 Answers

2
votes

While there now is a serverside container type for Google Tag Manager, GTM as we know and love it is a Javascript injector. All configured tags plus some boilerplate code are bundled in a file that you configure via the GTM interface. That is basically the last time GTM interacts with the server. All the tags, and the javascript code that executes them (selector engine, triggers etc.) are in the gtm.js file.

When you push something to the datalayer, it is not send to Google. Instead this is parsed by the GTM javascript that encapsulates the configured tags, and the values are made available to the tags. You could just as well host the file on your own server without any connection to the GTM server at all, it would still work.

So it is expected that there are no network requests. GTM will issue requests only if required by tracking tags bundled into the gtm.js file.