Server-side Google Tag Manager tracking made easier on Cloud Containers

Bring your Google Tag Manager tracking server-side with SiteHost. It just got a whole lot easier on Cloud Containers.

/
Date

Google Tag Manager logo sits on front of a grey blue abstract design background.

Since launching Cloud Containers, we’ve encouraged you to use them in whatever way you find useful.

While Cloud Containers are flexible by design, there will always be ways we can make your work easier or more straightforward. Your feedback guides the direction of the new tools we develop and new features we create. 

So when a customer reached out to us about using Cloud Containers for a server-side Google Tag Manager (GTM) implementation, we thought it was something that we could help streamline.

There could be a better way

The customer believed Cloud Containers could be a better fit for server-side GTM tracking than Google’s default Cloud Run service.

And that’s because hosting your server-side GTM tracking with Cloud Containers reduces latency for visitors, making use of servers hosted here in New Zealand equipped with stronger hardware than Cloud Run. All with the added benefit of keeping your hosting local.

As you’ll see, Cloud Containers can put more computing resources behind your GTM implementation at a lower cost than Cloud Run.

Ultimately, this customer spotted an opportunity to improve what they’re offering to their clients, and reached out to see if we could help.

Good idea. Here’s a new image

To better support server-side tracking, we’ve quickly made an unmodified instance of Google’s GTM Docker image available as a prebuilt image on Cloud Containers. Less than a week after the customer’s initial message we’d made this happen. This is the kind of thing we’re able to turn around quickly because our team is nimble and open to ideas from all of our customers.

Google typically releases official new Docker images every couple of months. On Cloud Run, you’re responsible for deploying these new images. Instead, we'll take on the burden of updating your image, automatically pulling the latest Docker packages from Google’s registry with a seven-day delay. This is so we can be sure there are no early bugs or other teething issues with a new image version. 

As well as keeping up-to-date with Google’s latest image updates, the Cloud Container platform abstracts away other fiddly things like the Docker runtime, the hosting setup and certificate provisioning. The only part of the setup that you need to dig into is environment variables, but that’s something you’d have to do wherever you set up server-side GTM.

If there’s an easier and more cost-effective way to implement server-side Google Tag Manager, we’d like to see it.

Merits of server side tagging

By default, GTM runs tagging code in your website visitor’s browser. That setup is free and straightforward, but it involves loading heavy scripts on the user’s browser (introducing latency), has compatibility issues with ad-blockers (tags get lost), and can introduce data privacy concerns. 

The alternative is server-side tagging. This method processes tags on a server (or Cloud Container), instead of on a user’s browser. User interactions are sent to your server before reaching your analytics or ads platforms. As the website owner, it means you get to keep more data, avoid browser restrictions (like ad-blockers), tighten up security because there are fewer third parties involved, and manually control what data is shared with each provider your GTM is linked into.

For your visitors there’s less latency with the reduced load on their browser.

Setting up GTM on Cloud Containers

If getting Cloud Containers to handle your server-side GTM tracking sounds like something that could work for you, there’s a few simple steps to follow to get it running.

You’re going to need to spin up two containers: one for previewing, one for tagging. The preview container is where the tagging container forwards the requests that were collected while you’re previewing. Cloud Container plans let you spin up multiple containers on one server, letting you manage both containers from the same space. Google’s automated setup strongly recommends running both of these environments to keep things running quickly and safely.

  • If you haven’t got one already, provision a server for your Cloud Containers in the SiteHost Control Panel.

  • Create a Container, and choose Google Tag Manager from our list of Web Images (this will be your preview container).

  • Create another container with the Google Tag Manager image (this will be your tagging container).

  • Configure your environment variables to match the variables in the Knowledge Base (if any of these are left blank or incorrect, the container will fail to start).

  • Enable SSL certificates for each container (Google Tag Manager expects servers to have HTTPS).

We’ve made setting up Cloud Containers with the new image as simple as possible, but there are still some steps on the Google end to get everything configured. If you’re already comfortable with server-side GTM, this will all be familiar to you. Otherwise, check out our Knowledge Base article Working with the Server-Side GTM Web Container for deeper instructions.

Running the numbers

We said earlier that Cloud Containers can give you more compute for less money than Google Cloud Run. Let’s dig into that.

Apples to apples

Google’s documentation estimates that Cloud Run will cost you ~$45 USD per server per month, so $90/mo USD for the recommended two server setup. Those prices will fluctuate up and down depending on your server’s resource usage, but in general ~$90 USD/mo for server instances kitted with 1 vCPU and 0.5GB memory is what you’ll be getting with Cloud Run.

Our recommended alternative approach is a 2-core 30 GB Standard Cloud Container, priced at NZ$80/mo. It’s a comparably priced, if not cheaper, setup than Cloud Run with far more solid specs.

Paying more, or getting more?

Then there’s the case where your compute requirements exceed Google’s average estimates. Cloud Run’s pricing is based on resource usage, so if your memory and compute usage exceeds Google’s estimates you’ll end up paying more. 

Our recommended 2-core  2GB RAM, 30 GB storage Cloud Container setup is a lot more powerful than Google’s recommended 2x Cloud Run instances with 1 vCPU and 0.5 GB of memory per server. Traffic spikes that could bloat your Google Cloud Run bill will likely fall within the headroom our recommended 2-core Cloud Container server provides.  

Cloud Container servers by design have a bit of room headroom for spikes like these. If traffic is consistently way higher than you’d expected, then you can always look to upgrade your plan.

Utilise resources you’re already paying for 

If you’re already running a Cloud Container server with room to spare, you may have space to add the GTM containers, without any extra expense. Even better—you could stop paying for Cloud Run or other extraneous external GTM servers altogether. It’s a clever way to utilise resources you’re already spending budget on.

And of course, if your server almost has enough room for the two GTM containers, you can easily upgrade the specs on your Cloud Container server.

Time, effort, and other costs

If you’re running a DIY server-side GTM setup somewhere else, take a look at what your implementation is costing you, including image maintenance, time and effort to keep things running, and weigh up if Cloud Containers may be the better option.

Cloud Containers also have the added perk of keeping your hosting in NZ, as well as reducing latency. Your costs stay reliably predictable, rather than being charged dynamically by Cloud Run for every single bit of memory, and compute power used. And of course, you get to use the SiteHost Control Panel you’re already familiar with.

Flexibility makes it possible

The message here isn’t just that we’ve added a new image to our Cloud Containers. 

In this case, a customer reached out wanting a feature, so we made it.

Because Cloud Containers are designed to be flexible, we were able to make it happen without much hassle. It serves as a good reminder that if you’re interested in using Cloud Containers in ways that our existing list of images doesn’t cover, then don’t hesitate to reach out. We take a proactive approach to Cloud Containers, and are focussed on making them more useful and making your work life easier.

Set up your first server-side GTM Cloud Containers today and let us know how it goes. If you have another idea for how Cloud Containers could make your life easier, get in touch.