Skip to content
Free AI visibility check: does your brand show up in ChatGPT and Gemini answers?Apply →

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

The order of operations for server-side Google Tag Manager, from the server container and a first-party domain to GA4, Google Ads, the Meta Conversions API and consent mode.

AuthorMahmud FiloğluReviewed byLast updated: View as Markdown
Cover of the server-side tracking setup post: 'sGTM setup' over a blue wave pattern

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; for how it differs from browser-based measurement, see 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.

OptionWhat it doesWhen 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 lineYou 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; 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:

OptionExampleServer-set cookiesSetup
Same origin (Google's best practice)www.yoursite.com/metricsFull accessA CDN or load balancer that forwards requests; possibly DNS changes
Subdomainmetrics.yoursite.comFull accessUpdate DNS records
Default domainmetrics.run.appNone; JavaScript cookies onlyPreconfigured

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.

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?

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?

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. 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.

Frequently asked questions

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.

Sources

  1. 1Google for Developers, An introduction to server-side tagging, 2026
  2. 2Google for Developers, Why and when to use server-side tagging?, 2026
  3. 3Google for Developers, Setting up a new server container, 2026
  4. 4Google for Developers, Set up server-side tagging with Cloud Run, 2026
  5. 5Google for Developers, Manual setup guide, 2026
  6. 6Google for Developers, Planning infrastructure requirements and costs, 2026
  7. 7Google for Developers, Upgrade your servers for live traffic, 2026
  8. 8Google for Developers, Custom domain configuration, 2026
  9. 9Google for Developers, Configuring the Google Analytics data stream, 2026
  10. 10Google for Developers, Send data to server-side Tag Manager, 2026
  11. 11Google for Developers, Google Ads conversions, 2026
  12. 12Meta for Developers, Conversions API for Server-Side Google Tag Manager (GTM), 2026
  13. 13Meta for Developers, Handling Duplicate Pixel and Conversions API Events, 2026
  14. 14Meta for Developers, Customer Information Parameters, 2026
  15. 15Google for Developers, Implement consent mode with server-side Tag Manager, 2026
  16. 16Google for Developers, Preview and debug server containers, 2026

About the author

Senior Software Engineer & Tech Lead

Semih Bayındır is a Senior Software Engineer & Tech Lead with advanced technical expertise and strong experience in software architecture and modern development technologies.

All their posts

The service this post relates toServer-side trackingServer-side Google Tag Manager, first-party data, Meta Conversions API and enhanced conversions: send ad signals that are complete and under your control.

More posts

All Analytics and Data posts

Let’s put what you read to work for you.

In a 30-minute intro we look at your account and tell you which step should come first.

Ask Ezgi