All guides
Server60 min· Advanced

Spin up server-side GTM on Cloud Run

From zero to a production sGTM container on Google Cloud Run, served on a first-party subdomain with SSL — ready to host CAPI, TikTok EAPI, and Microsoft UET server tags.

Before you start — you'll need
  • Google Cloud project (billing enabled — free tier covers low traffic)
  • Domain you own + DNS access
  • GTM admin access
By the end you'll have
  • sGTM tagging server live at sgtm.yourdomain.com
  • HTTPS via Google-managed certificate
  • Auto-provisioning script (one-line deploy)
  • GTM web container forwarding to it via Server Container URL
Step 1

Create the server container in GTM

GTM → Admin → Create Container → Server. Pick Manually provision tagging server. Note the Container Config long string — you'll need it.

Step 2

Provision Cloud Run via Google's setup script

Google ship an official one-click setup. In Cloud Console open Cloud Shell and run:

bash -c "$(curl -fsSL https://googletagmanager.com/static/serverjs/setup.sh)"
Tip: The script will ask for the Container Config, deployment type (testing vs production), and number of instances (start with min=1, max=5 for production).
Step 3

Map your custom domain

Cloud Run → your service → Custom Domains → Add Mapping → Add domain. Enter sgtm.yourdomain.com. Google gives you a CNAME record. Add it in your DNS host. Wait 10–60 min for SSL provisioning.

Tip: First-party subdomain is non-negotiable. Without it, Safari ITP destroys your match rates and the whole point of sGTM is lost.
Step 4

Point the web container at sGTM

In your GTM web container → open the Google Tag → Configuration settings → Server Container URL: https://sgtm.yourdomain.com. Save & Submit.

For Meta/TikTok pixels, do the same on each pixel template's First-Party / Server Container URL field.

Step 5

Install GA4 client + tag in sGTM

sGTM → Clients → New → Google Analytics: GA4. Default settings. Save.

Tags → New → Google Analytics: GA4. Measurement ID: your G-XXXXXXXXXX. Trigger: All Events. This is what relays GA4 hits from browser → sGTM → Google.

Step 6

Verify with Preview

sGTM has its own Preview button. Hit it, then browse your site. You should see every event from the web container arriving in the sGTM Preview, with the GA4 tag firing and the request to https://www.google-analytics.com/g/collect in the network log.

Step 7

Add CAPI / TikTok EAPI / UET on top

With the foundation working, layer on the per-platform server tags. See the Meta and TikTok how-tos for the specifics. Each one piggy-backs on the same incoming event stream.

Common pitfalls
  • Using a vendor subdomain (e.g. sgtm.stape.io) instead of your own — defeats the first-party benefit.
  • Min instances = 0 — cold starts add ~2s latency to early events; set min=1 for production.
  • Forgetting to set Cloud Run concurrency higher than 1 — costs explode at any real traffic.
  • Not enabling Cloud Logging — when EMQ drops you'll have no idea why.
Official references
Keep going