Most people run server-side Google Tag Manager through a hosting service such as Stape, which bills by the number of requests. At the time of writing its plans go from $17 a month for 500,000 requests to $83 a month for 5 million (pricing overview).
Google publishes the tagging server as a Docker image and explains how to run it yourself in its manual setup guide. If you already have a Linux server, that costs you nothing extra per request. I did that for a few sites, kept repeating the same steps and turned them into a small open-source script called tagdock.
What it does
tagdock starts the preview server and the tagging server that Google's guide describes, puts Caddy in front for HTTPS and can run several containers on one server, for example one per client. When you add a site it asks for the Container Config, tells you which GTM container it belongs to and warns when a domain does not point to the server yet.
The part that bit me
One of my tagging servers lost its DNS for a moment, could not reach Google and stayed unhealthy for weeks afterwards. Docker kept it running, because it does not restart unhealthy containers on its own. That is why tagdock has a heal command that restarts them, and an update command for new images. Both run fine from cron.
The trade-off
A hosted service scales the servers for you and adds its own features. With tagdock you run the containers on your own machine and keeping it up is your job. For a few sites on a server I already maintain, that works well for me.
The setup takes five commands and is in the README. Feedback and issues are welcome.
Top comments (1)
the dns-blip story is doing more work than the cost argument. five commands to set up is cheap, but a tagging server that goes unhealthy and just sits there costs you the data you didn't know you were missing. does tagdock alert you when that happens, or do you find out at the next deploy?