google-tag-managergoogle-tag-manager-server-side

Can I render google tag manager scripts server side?


I'm looking into google tag manager and would like to avoid making a request from the client to render the tags. Is it possible to request the tags from GTM on the server and render them up front?


Solution

  • No (*). Not only is GTM itself a client-side technology, most marketing tags likewise require to be run in the browser.

    There are a few things like Google Analytics or Google Ads conversion tags that can be run on the server (although the implementation is very much different from the JS tags), but GTM has no part in that. If you want vaguely similar functionality to GTM that moves at least a part of your tags out of the client-side code you should look at a service like segment.com (I am not affiliated. Segment.com is not free).

    Update Feb 2020: Google has announced a closed beta for server-side tracking, where you run a container in a cloud environment that then distributes the requests. Simo Ahava has a little info in his twitter feed: https://twitter.com/SimoAhava/status/1222459714614841346. This is not yet a production feature.

    (*) Not in any meaningful sense of the world. Just to cover every angle, you could download the GTM javascript file and run it in a headless browser on the server or something similarly stupid, but there would be no point, and I just mentioning it to pre-empt smartass comment to that effect.