---
type: "Blog Post"
title: "How to set up server-side tracking with sGTM | Roicool"
description: "How to set up server-side tracking with sGTM: Cloud Run sizing and cost, a first-party domain, GA4, Google Ads, Meta CAPI and consent mode."
url: "https://www.roicool.com/en/blog/how-to-set-up-server-side-tracking"
lang: "en"
dateModified: "2026-11-18"
author: "Semih Bayındır"
resource: "https://www.roicool.com/en/blog/how-to-set-up-server-side-tracking"
alternates:
  tr: "https://www.roicool.com/blog/server-side-tracking-kurulumu.md"
generated: { by: "process:roicool-cms", at: "2026-11-18T11:33:13.404Z" }
related:
  - { title: "What is Meta Conversions API? Setting it up right alongside the Pixel", resource: "https://www.roicool.com/en/blog/what-is-meta-conversions-api.md" }
  - { title: "What is Consent Mode v2? Cookie consent and Google measurement", resource: "https://www.roicool.com/en/blog/what-is-consent-mode-v2.md" }
  - { title: "What Is Google Tag Manager? From the Container Snippet to Server-Side Tagging", resource: "https://www.roicool.com/en/blog/what-is-google-tag-manager.md" }
sources:
  - { id: "1", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/intro", title: "Google for Developers, An introduction to server-side tagging" }
  - { id: "2", resource: "https://developers.google.com/tag-platform/learn/sst-fundamentals/3-why-and-when-sst", title: "Google for Developers, Why and when to use server-side tagging?" }
  - { id: "3", resource: "https://developers.google.com/tag-platform/learn/sst-fundamentals/4-sst-setup-container", title: "Google for Developers, Setting up a new server container" }
  - { id: "4", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/cloud-run-setup-guide", title: "Google for Developers, Set up server-side tagging with Cloud Run" }
  - { id: "5", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/manual-setup-guide", title: "Google for Developers, Manual setup guide" }
  - { id: "6", resource: "https://developers.google.com/tag-platform/learn/sst-fundamentals/7-planning-infrastructure", title: "Google for Developers, Planning infrastructure requirements and costs" }
  - { id: "7", resource: "https://developers.google.com/tag-platform/learn/sst-fundamentals/8-upgrade-infrastructure", title: "Google for Developers, Upgrade your servers for live traffic" }
  - { id: "8", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/custom-domain", title: "Google for Developers, Custom domain configuration" }
  - { id: "9", resource: "https://developers.google.com/tag-platform/learn/sst-fundamentals/5-sst-setup-analytics", title: "Google for Developers, Configuring the Google Analytics data stream" }
  - { id: "10", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/send-data", title: "Google for Developers, Send data to server-side Tag Manager" }
  - { id: "11", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/ads-setup", title: "Google for Developers, Google Ads conversions" }
  - { id: "12", resource: "https://developers.facebook.com/docs/marketing-api/conversions-api/guides/gtm-server-side/", title: "Meta for Developers, Conversions API for Server-Side Google Tag Manager (GTM)" }
  - { id: "13", resource: "https://developers.facebook.com/documentation/ads-commerce/conversions-api/deduplicate-pixel-and-server-events", title: "Meta for Developers, Handling Duplicate Pixel and Conversions API Events" }
  - { id: "14", resource: "https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters", title: "Meta for Developers, Customer Information Parameters" }
  - { id: "15", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/consent-mode", title: "Google for Developers, Implement consent mode with server-side Tag Manager" }
  - { id: "16", resource: "https://developers.google.com/tag-platform/tag-manager/server-side/debug", title: "Google for Developers, Preview and debug server containers" }
---

# How to set up server-side tracking: a step-by-step sGTM guide

Create a server container in Tag Manager, run it on Cloud Run sized for live traffic, and map it to a subdomain of your site. Point your Google tag at it with server\_container\_url, then set up GA4, Google Ads and Meta tags on the server and check them with consent mode and preview.

- A server container runs on your server, not in the browser, so you can filter data before vendors see it.
- Tag Manager's automatic Cloud Run setup is for testing only; upgrade the server before sending live traffic.
- Google's two guides call for at least 2 or 3 instances at about $45–50 per instance per month.
- Map the server to the same origin or a subdomain of your site to get first-party cookie benefits.
- Give the Pixel and server events the same event name and event\_id so Meta can deduplicate them.
- Consent mode lives in the web container; tie non-Google tags to consent status separately.

Setting up server-side tracking means moving some of your measurement tags out of the visitor's browser and onto a server you control. In practice, most teams do this with server-side Google Tag Manager (sGTM): the browser sends one stream of data to your server, and the server container routes it to GA4, Google Ads and Meta according to rules you define. For the definition, see the [server-side tracking glossary entry](https://www.roicool.com/en/glossary/server-side-tracking); for how it differs from browser-based measurement, see [server-side vs. client-side tracking](https://www.roicool.com/en/comparisons/server-side-vs-client-side-tracking). This guide covers the setup itself: the order of operations, the settings that matter and the places where setups usually go wrong.

The steps follow Google's sGTM developer documentation and Meta's Conversions API documentation. Menu names and defaults change over time, so open the relevant page and check the current version before you start.

## How server-side GTM works

According to Google's "An introduction to server-side tagging," a server container doesn't run in the user's browser or on their phone. It runs on a server you control, in your own Google Cloud project or another environment you choose, and only you have access to the data on it until you decide to send it somewhere else.

Tags, triggers and variables work the way they do in a web container. The new piece is the **client**. A client receives a request from a device, turns it into one or more events, runs those events through the container and packages the response. Clients evaluate each request in priority order, and the first one that "claims" it handles it; the others stand aside. Every server container ships with two clients: Google Analytics and Measurement Protocol.

The "Why and when to use server-side tagging?" chapter in Google's learning center gives three reasons to bother: privacy control, site performance and data quality. In a browser-based setup, the user's IP address goes out with every request to every vendor. On the server, you can validate, anonymize or block a request before it reaches a vendor. The same chapter notes that, in a first-party context, cookies can be set with the HttpOnly flag, and that you can enrich events on the server with data you'd never expose to the browser, such as profit margins.

## What you need before you start

Google's Cloud Run setup guide and learning center list these prerequisites:

- A Google Cloud (GCP) account and billing account, plus the Project Creator and Billing Account User roles.
- A Google Tag Manager account with permission to create a server container.
- A GTM web container or a Google tag on your site as the data source.
- A GA4 property to use as the example data stream.
- Optional but recommended: a subdomain of your site for a first-party context (for example, `metrics.yoursite.com`).

Add one internal decision to that list: who will run the server? Google's "Planning infrastructure requirements and costs" chapter points out that Cloud Run takes some Google Cloud know-how, and that if your company already has Google Cloud policies in place, you should walk through the upgrade with IT or DevOps.

## Step 1: Create the server container and provision a server

In Tag Manager, create a new container from your account menu and choose **Server** as the type. The setup screen offers two paths: automatic provisioning from inside Tag Manager, or provisioning the server yourself.

| Option | What it does | When to use it |
| --- | --- | --- |
| Automatic (Cloud Run) | Creates a Google Cloud project with a preview server and a single tagging server. The region is fixed to us-central1. | Testing only. Google says it doesn't support a production workload; you upgrade it later. |
| Cloud Run console or Cloud Shell command line | You choose the region and the autoscaling limits. | When you want control over region and scaling for production. |
| Manual (Docker) | The tagging server is a Node.js server in a Docker image that runs in any environment with public HTTP access. | When you need to host outside Google Cloud. The hardest option to set up. |

After automatic provisioning, confirm the server is up: add `/healthy` to the end of the server URL and open it. You should see "ok."

If you go the manual route, three rules from Google's "Manual setup guide" matter most. Run exactly **one** preview server and don't autoscale it past one instance. Give your load balancer or CDN a timeout longer than 20 seconds, or preview mode won't work properly. And give tagging servers no more than 1 vCPU; extra vCPUs go unused and hurt autoscaling. The same page also warns that whoever owns the server environment, whether a cloud provider or your own data center, may have access to your data, so read their terms of service.

## Step 2: Size the server for live traffic and estimate cost

The test server isn't built for live traffic, so you upgrade the Cloud Run settings before launch. Google's "Set up server-side tagging with Cloud Run" guide gives these figures:

- Each server costs about **$45 a month** (1 vCPU, 0.5 GB of memory, on the CPU-always-allocated pricing model).
- Google recommends at least **2 instances** to reduce the risk of data loss if a server goes down.
- Autoscaling between 2 and 10 servers is expected to handle 35 to 350 requests per second, though real performance depends on how many tags you run and what they do.
- Max instances is your [worst-case cost](https://www.roicool.com/en/tools/server-side-tracking-cost-calculator); Cloud Run won't spin up that many unless it needs them.

Google's learning center uses different numbers: the "Upgrade your servers for live traffic" chapter recommends a minimum of 3 instances and 3 to 6 instances for 50 to 200 requests per second, and the "Planning infrastructure requirements and costs" chapter puts the price at roughly $50 per instance per month. Be aware of the gap between the two sources and run your own estimate in the Google Cloud pricing calculator based on your traffic.

Logging is the line item people miss. Per the Cloud Run guide, every request is logged by default, and on a server handling more than a million requests a month those logs can add significant charges, so Google recommends turning request logging off. Set up a billing alert as well, so a traffic spike doesn't turn into a surprise invoice.

## Step 3: Map the server to a first-party domain

A new tagging server runs on an address your cloud provider assigns (such as `…run.app`), which puts it in a third-party context. Google's "Custom domain configuration" page explains that to get first-party benefits like more durable cookies, your tagging server and your website have to run on the same domain. You have three options:

| Option | Example | Server-set cookies | Setup |
| --- | --- | --- | --- |
| Same origin (Google's best practice) | `www.yoursite.com/metrics` | Full access | A CDN or load balancer that forwards requests; possibly DNS changes |
| Subdomain | `metrics.yoursite.com` | Full access | Update DNS records |
| Default domain | `metrics.run.app` | None; JavaScript cookies only | Preconfigured |

Google's introduction "strongly" recommends putting the server on your first-party domain and switching it to production mode before you send it any production traffic. Once the domain is mapped, update the server container URL in Tag Manager under **Admin > Container Settings**.

## Step 4: Send data from your site to the server

Google recommends the Google tag running in the browser as the data source. In your web container, create a **Google tag**, enter your tag ID, and under configuration settings add the `server_container_url` parameter with your server URL as the value. If you use gtag.js, the same parameter goes in the `gtag('config', …)` call.

Don't cut over all at once. Google's learning center suggests leaving your existing GA4 setup alone, creating a new GA4 property for the server-side stream, and copying tags over one by one so you run both in parallel (dual tagging) for a while. When server-side measurement matches client-side, you point your tags at the server and remove the duplicate setup. Sending some vendors data from the browser and others from the server is also a common hybrid approach.

If your site uses a Content Security Policy, Google's "Send data to server-side Tag Manager" page says to add your server URL to the `img-src` and `connect-src` directives, and to `frame-src` for the service worker method. The `X-Frame-Options` header also must not block iframes loaded from the server URL.

## Step 5: Configure the GA4 client, tag and trigger

The GA4 client comes preinstalled in every server container. Google's learning center walks through the setup:

1. **Client:** Leave the default GA4 paths checked so the client claims requests like `/g/collect`. Set cookies and client identification to "JavaScript Managed" until your custom domain is in place; once you have a first-party domain, you can switch to a server-managed cookie.
2. **Tag:** Create a new *Google Analytics: GA4* tag and leave the fields at their defaults. The tag inherits the measurement ID and event parameters from the event data the client creates.
3. **Trigger:** Create a Custom trigger with a *Client Name* condition so it fires only on events from the GA4 client. Because a server container can rack up compute and network costs, Google suggests setting limits early, even during testing.

If you send extra parameters, create a user-defined variable of type *Event Data* and enter the parameter name as the key path to use it in other server tags.

## Step 6: Move Google Ads conversions to the server

According to Google's "Google Ads conversions" page for sGTM, moving Ads conversion tags to the server reduces the code running on the page and helps page load speed. The order is:

1. Set up a **Conversion Linker** tag in the server container. In most cases it fires on all pages.
2. Mark the conversion event as a key event in GA4, and send it with a GA4 event tag from the web container.
3. Create a **Google Ads Conversion Tracking** tag in the server container, enter the conversion ID and label from your Google Ads account, and trigger it on the event name.

For enhanced conversions, the event parameter that carries the user-provided data variable must be named `user_data`. Google requires this so hashed user data and enhanced conversions work correctly. If your sales close in a CRM, importing those conversions later is a separate workflow, covered in [Google Ads offline conversion tracking](https://www.roicool.com/en/blog/google-ads-offline-conversion-tracking).

## Step 7: Feed the Meta Conversions API from the same stream

For the Meta Conversions API (CAPI), Meta's "Conversions API for Server-Side Google Tag Manager (GTM)" page builds on the GA4 stream:

1. **Web container:** In the GA4 configuration, point to your server URL and set `first_party_collection` to `true`. Meta says this is required to pass `user_data` parameters. In the GA4 event tag, use the Meta standard event name (for example, `Lead`) or the mapped GA4 name.
2. **Server container:** Add the Conversions API tag that Meta writes and maintains from the Template Gallery. It needs your Pixel ID and an access token. Set the action source to "website" and trigger the tag on events from the GA4 client.
3. **Deduplication:** Give the browser-side Meta Pixel tag and the GA4 event tag the same trigger, the same event name and the same `event_id`.

Meta also notes that server-side GTM needs a browser-based tag to emit events, and that you should remove the `test_event_code` before publishing. Per Meta's "Handling Duplicate Pixel and Conversions API Events," events are only deduplicated if they arrive within 48 hours of the first event with a given `event_id`, and Meta recommends running the Conversions API alongside the Pixel for the best ad performance.

When you send customer information, follow the hashing rules on Meta's "Customer Information Parameters" page: contact fields such as email, phone, first name and last name are normalized and hashed with SHA-256, while `client_ip_address`, `client_user_agent`, `fbc` and `fbp` must not be hashed. For how the Pixel and the Conversions API differ, and how match quality works, see [What is Meta Conversions API?](https://www.roicool.com/en/blog/what-is-meta-conversions-api)

## Step 8: Connect consent mode to the server setup

Google's "Implement consent mode with server-side Tag Manager" page describes the flow: the consent banner on your site passes the user's choices to the Google tag, the Google tag adds them to the HTTP request as consent parameters and sends it to the server container, and Google product tags on the server adjust how much and what kind of data they send. That's why you only need to set up consent mode in the web container. A few examples:

- With the **basic** implementation, if a user hasn't consented to analytics cookies, Google tags don't load at all, and no Analytics cookies are set or read on either the client or the server.
- The **Google Ads conversion tag** doesn't write or read Ads cookies when `ad_storage` is denied; instead, the browser sends a conversion pixel to a domain without third-party cookies. Enhanced conversions work only when consent is granted.
- The **Google Ads remarketing tag** blocks HTTP requests and cookie use when `ad_storage` is denied.

Google's page describes this automatic behavior for Google product tags. Plan separately how you'll tie other vendors' tags, such as the Meta Conversions API tag, to consent status, and test it in preview with a session where consent was denied. For consent mode itself and the v2 parameters, see [What is Consent Mode v2?](https://www.roicool.com/en/blog/what-is-consent-mode-v2)

A technical setup doesn't make you compliant on its own. This article isn't legal advice; review which data goes to which vendor, and on what legal basis, with your own counsel.

## Step 9: Preview, validate and cut over

Click **Preview** in the server container and open your site in a separate tab. According to Google's "Preview and debug server containers" page, the left panel lists incoming HTTP requests (such as `collect?v=2…`) and the events created from them. For each request, check three things:

- **Client:** Did the right client claim the request?
- **Incoming request:** Does it match what you see in the browser's Network tab, and are the parameters you expect arriving?
- **Outgoing requests:** Which tag sent what to which vendor, and what status code came back?

Once preview looks right, run browser-side and server-side measurement in parallel for a while and compare the numbers in GA4, Google Ads and Meta Events Manager. When they line up, remove the duplicate browser tags. If you provisioned the server manually, put updates on the calendar too: Google says the Docker image is updated regularly for security fixes and new features, and recommends updating at least for every major version (for example, from 1.x.x to 2.x.x).

## After setup: tools and maintenance

Instead of running sGTM in your own Google Cloud project, you can also use managed hosting or packaged server-side tracking tools; we compare the options in our list of the [best server-side tracking tools](https://www.roicool.com/en/lists/best-server-side-tracking-tools-2027). Whichever route you take, a server-side setup isn't something you build once and forget. Every new conversion, new vendor or change to your consent banner calls for another round of preview and comparison.

Roicool sets up server-side Google Tag Manager; the scope and process are on our [server-side tracking service page](https://www.roicool.com/en/services/server-side-tracking).

## Sources

1. [Google for Developers, An introduction to server-side tagging](https://developers.google.com/tag-platform/tag-manager/server-side/intro), 2026
2. [Google for Developers, Why and when to use server-side tagging?](https://developers.google.com/tag-platform/learn/sst-fundamentals/3-why-and-when-sst), 2026
3. [Google for Developers, Setting up a new server container](https://developers.google.com/tag-platform/learn/sst-fundamentals/4-sst-setup-container), 2026
4. [Google for Developers, Set up server-side tagging with Cloud Run](https://developers.google.com/tag-platform/tag-manager/server-side/cloud-run-setup-guide), 2026
5. [Google for Developers, Manual setup guide](https://developers.google.com/tag-platform/tag-manager/server-side/manual-setup-guide), 2026
6. [Google for Developers, Planning infrastructure requirements and costs](https://developers.google.com/tag-platform/learn/sst-fundamentals/7-planning-infrastructure), 2026
7. [Google for Developers, Upgrade your servers for live traffic](https://developers.google.com/tag-platform/learn/sst-fundamentals/8-upgrade-infrastructure), 2026
8. [Google for Developers, Custom domain configuration](https://developers.google.com/tag-platform/tag-manager/server-side/custom-domain), 2026
9. [Google for Developers, Configuring the Google Analytics data stream](https://developers.google.com/tag-platform/learn/sst-fundamentals/5-sst-setup-analytics), 2026
10. [Google for Developers, Send data to server-side Tag Manager](https://developers.google.com/tag-platform/tag-manager/server-side/send-data), 2026
11. [Google for Developers, Google Ads conversions](https://developers.google.com/tag-platform/tag-manager/server-side/ads-setup), 2026
12. [Meta for Developers, Conversions API for Server-Side Google Tag Manager (GTM)](https://developers.facebook.com/docs/marketing-api/conversions-api/guides/gtm-server-side/), 2026
13. [Meta for Developers, Handling Duplicate Pixel and Conversions API Events](https://developers.facebook.com/documentation/ads-commerce/conversions-api/deduplicate-pixel-and-server-events), 2026
14. [Meta for Developers, Customer Information Parameters](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters), 2026
15. [Google for Developers, Implement consent mode with server-side Tag Manager](https://developers.google.com/tag-platform/tag-manager/server-side/consent-mode), 2026
16. [Google for Developers, Preview and debug server containers](https://developers.google.com/tag-platform/tag-manager/server-side/debug), 2026

## FAQ

### What makes up the cost of server-side GTM?

Google's learning center splits Cloud Run cost into three parts: compute, which is mostly fixed by the number of instances you keep running; network egress, which moves with traffic and covers data sent to vendors and back to the browser; and log storage, which can grow once you pass the Cloud Logging free tier. If the server also serves larger files such as JavaScript libraries, egress can become a noticeable line item.

### Can I remove the browser-side tags after moving to server-side?

Not entirely. The server container doesn't collect data on its own; in Google's recommended setup, the Google tag in the browser sends it the requests, either through a GTM web container or directly with gtag.js. Meta also says server-side GTM needs a browser-based tag to send events. What you remove are the browser copies of the vendor tags you've moved to the server.

### Can a mobile app or backend send data to the server container?

Yes. Per Google's documentation, you add a Measurement Protocol client to the server container and give it an activation path. Android and iOS apps can hit that path through a custom image tag in the mobile container, and server-to-server systems send to your server container's domain instead of the Google Analytics hostname. Google notes this route doesn't support every Measurement Protocol endpoint feature; for example, it doesn't derive geographic and device information from the events.

### Can several websites share one server container?

Yes. Google's learning center says you can add multiple custom domains to the service when one server container receives requests from several sites. To preview on each domain, add the extra server container URLs under Container Settings; per Google's manual setup guide, all of those URLs must share the same path after the domain.

### Can I change the Cloud Run region later?

Automatic provisioning creates the service in us-central1. According to Google's learning center, changing the region means creating a new service in the new region in the Cloud Run console and deleting the old one. To serve several geographies, you can run more than one service behind a load balancer.

Breadcrumb: [Home](https://www.roicool.com/en) › [Blog](https://www.roicool.com/en/blog) › [Analytics and Data](https://www.roicool.com/en/blog/category/analytics) › How to set up server-side tracking: a step-by-step sGTM guide

Related pages:

- [What is Meta Conversions API? Setting it up right alongside the Pixel](https://www.roicool.com/en/blog/what-is-meta-conversions-api)
- [What is Consent Mode v2? Cookie consent and Google measurement](https://www.roicool.com/en/blog/what-is-consent-mode-v2)
- [What Is Google Tag Manager? From the Container Snippet to Server-Side Tagging](https://www.roicool.com/en/blog/what-is-google-tag-manager)

Source: https://www.roicool.com/en/blog/how-to-set-up-server-side-tracking · Last updated: 2026-11-18
