How to set up Google Tag Manager server side

Learn how to set up Google Tag Manager server side. This guide covers hosting, DNS, and moving tags from the browser to your server.

Eptekhar Hasan7 min read

Server-side Google Tag Manager (sGTM) moves your tracking code from the user's browser to a server you control. This reduces ad blocker impact and improves data reliability. You host the container, point your domain to it, and update your client-side tags to send data to the server instead of directly to Google. This guide walks you through the entire process, from initial setup to final verification.

Why move to server-side tracking

Ad blockers and privacy laws are changing how websites collect data. When you run tags directly in the browser, users can block them. Your data becomes incomplete. Server-side tracking solves this by sending data to your own server first. Your server then forwards the data to Google Analytics, Google Ads, or Meta. The user only sees a request to your domain, not to Google.

This setup offers three main benefits:

  • Ad blocker resistance: Most ad blockers do not block requests to your own domain.
  • Data control: You can clean, modify, or enrich data before it leaves your server.
  • Performance: The browser makes fewer external requests, which can speed up page loads.

However, it is not a magic fix. It adds complexity. You need a place to host the server container. You need to manage DNS records. You need to update your existing tags. If you are not comfortable with these technical steps, you might want to consider server-side tracking services that handle the infrastructure for you.

Step 1: Choose your hosting environment

You need a server to run your sGTM container. Google provides a free Docker image, but you must host it yourself. You have three main options:

  1. Cloud Platform: Use Google Cloud Platform (GCP), AWS, or Azure. This is the most flexible option. You can spin up a small instance for a few dollars a month.
  2. Existing VPS: Use a Virtual Private Server if you already have one.
  3. PaaS: Use a platform like Heroku or Render. This is easier to manage but can be more expensive at scale.

For most small businesses and coaches, a small instance on GCP or AWS is the best balance of cost and control. You do not need a powerful server. sGTM is lightweight. A 1 vCPU and 1GB RAM instance is usually sufficient.

Step 2: Create your server container

Log in to your Google Tag Manager account. Create a new container and select "Server" as the type. Name it something clear, like "Production Server Container." Once created, you will see a preview URL and a publish button.

Click "Publish" to create the initial version. This generates the server-side container that you will host. Note the container ID. It looks like GTM-XXXXXXX. You will need this ID for the next step.

Step 3: Deploy the container to your server

You need to run the sGTM Docker container on your chosen host. If you are using GCP, you can use Cloud Run or Compute Engine. Here is a general outline for a Docker setup:

  1. Pull the official sGTM image from Docker Hub.
  2. Create a .env file with your container ID and any custom settings.
  3. Run the container with the necessary environment variables.

The container listens on port 80 by default. You will need to forward traffic to this port. If you are using a load balancer, point it to your container. If you are using a simple VPS, configure your firewall to allow inbound traffic on port 80 and 443.

Step 4: Configure DNS records

Your sGTM container needs a dedicated subdomain. Do not use your main domain. Use a subdomain like tag.yourdomain.com or analytics.yourdomain.com.

Log in to your DNS provider. Create two A records or one CNAME record pointing to your server's IP address or hostname.

  • Record Type: A
  • Name: tag
  • Value: <your-server-ip>

Wait for the DNS changes to propagate. This can take anywhere from a few minutes to 24 hours. You can check propagation using a DNS lookup tool.

Step 5: Set up SSL certificates

You must serve your sGTM container over HTTPS. Browsers will block mixed content if your main site is HTTPS and your tag is HTTP.

If you are using GCP or AWS, you can use their managed certificate services. If you are using a VPS, use Let's Encrypt.

For Let's Encrypt, run certbot on your server. Point it to your subdomain. This generates a certificate and configures your web server (Nginx or Apache) to use it.

After this step, visit https://tag.yourdomain.com in your browser. You should see a message saying the container is running. If you see an error, check your server logs and firewall rules.

Step 6: Update your client-side tags

Now you need to update your existing tags in your client-side GTM container. You are not deleting them. You are changing where they send data.

  1. Open your client-side GTM container.
  2. Go to Tags.
  3. Edit your Google Analytics 4 Configuration tag.
  4. In the Measurement ID field, keep your ID.
  5. Add a new field: Server Container URL.
  6. Enter your sGTM URL: https://tag.yourdomain.com.

Repeat this for all Google tags you want to move. This includes Google Ads conversion tags, GA4 event tags, and Remarketing tags.

Do not change your Meta Pixel or other third-party tags yet. You can move them later, but start with Google products. They are the easiest to migrate.

Step 7: Verify the data flow

You need to confirm that data is flowing through your server.

  1. Open your website in an incognito window.
  2. Open browser developer tools.
  3. Go to the Network tab.
  4. Filter by tag.yourdomain.com.
  5. Refresh the page.

You should see a request to your server. The status code should be 200. If you see a 404 or 500 error, your server is not responding correctly.

Next, check Google Analytics. Go to Realtime reports. You should see active users. If you do not see data, check the DebugView in Google Analytics. This shows you exactly which events are being received.

If you are not sure if the setup is working, you can use this GTM checker to see if your tags are firing correctly. It tells you if the server-side container is receiving requests and if the data is being forwarded to Google Analytics.

Common issues and how to fix them

Even with a careful setup, things can go wrong. Here are the most common problems:

  • CORS errors: If you see CORS errors in your browser console, your server is not sending the correct headers. Add the Access-Control-Allow-Origin header to your server response.
  • Slow page loads: If your server is slow, it will slow down your website. Monitor your server's response time. Keep it under 100ms.
  • Duplicate data: If you forget to remove the old direct tags, you might send data twice. Make sure you only send data through the server, not directly to Google.
  • SSL errors: If your certificate expires, your tags will stop working. Set up automatic renewal for your SSL certificates.

Testing and debugging

Use GTM Preview mode to test your changes. Click Preview in GTM, enter your website URL, and open the preview window.

Look for the server-side container in the list of tags. It should show as "Fired." Click on it to see the details. You can view the payload sent to your server.

Check the Server Container tab in the preview. This shows you the data your server received. Compare it to what you expect. If the data is missing, check your client-side tag configuration.

You can also use the Data Preview tab to see the raw data. This is useful for debugging complex events.

When to hire help

Setting up sGTM is technical. If you are not comfortable with servers, DNS, or Docker, you might make mistakes that cost you data. A small configuration error can mean you lose months of analytics data.

Working with a specialist can save you time and stress. They can set up the infrastructure, configure the tags, and verify the data flow. You can learn more about how we handle this for businesses in our server-side tracking guide.

Final checklist

Before you consider the setup complete, run through this list:

  • Server container is running and accessible via HTTPS.
  • DNS records are pointing to the correct server.
  • SSL certificate is valid and not expiring soon.
  • Client-side tags are updated with the server URL.
  • Data is appearing in Google Analytics Realtime reports.
  • No duplicate data is being sent.
  • Server response time is under 100ms.

Server-side tracking is a powerful tool. It gives you more control over your data and reduces the impact of ad blockers. But it requires ongoing maintenance. You need to monitor your server, update your tags, and keep your SSL certificates current.

If you decide to manage it yourself, take it step by step. Test each change before moving to the next. Keep a backup of your GTM container before you make major changes.

For more on how to optimize your tracking setup, read our article on what is Google Tag Manager and how it works. Understanding the basics will help you troubleshoot any issues that arise.

If you have questions about your specific setup, you can reach out to us. We help small businesses and coaches get their tracking right. Check out our pricing page to see how we can help.

Remember, the goal is reliable data. If your data is incomplete, your marketing decisions will be flawed. Server-side tracking helps you get the full picture. Take the time to set it up correctly. Your future self will thank you.

Keep reading

All guides