WooCommerce plugin has been released on WordPress.orgView plugin →

GA4 Server-Side Tracking Setup, Step by Step (Tested)

Set up GA4 through a server-side GTM container: the web and server settings, how to check it works, and the cookie setting that silently fails on the wrong domain.

MHMahmudul HasanNov 15, 20267 min read
Tested 15 November 2026
The short answer

To send GA4 through server-side GTM, point the Google tag in your web container at your tagging server with the server_container_url setting, and in the server container keep the built-in GA4 client and add a GA4 tag that fires on the events that client claims. Your pages then send /g/collect requests to your own subdomain instead of google-analytics.com, and the server forwards them to Google. Run the server on a subdomain of your own site (for example track.yourstore.com): on any other domain, cookies set by the server are thrown away by the browser.

TagLinc hosts server-side GTM, so we are not neutral. The numbers and settings below come from a test on 15 November 2026 on our own Shopify development store: a web GTM container sending to a TagLinc server container. The store uses a test GA4 measurement ID, so we checked arrival at the server container (our event logs) rather than in GA4's Realtime report.

What changes compared with normal GA4

Normally the browser sends GA4 events straight to Google. With server-side tagging the browser sends them to your tagging server, which then sends them on. Three things follow:

  • Requests go to a domain you control, so fewer are lost to ad blockers and you can see every one of them.
  • The server can set cookies itself (on your own subdomain), which browsers like Safari keep for longer than cookies set by JavaScript.
  • You can add other server tags (Meta Conversions API, Google Ads) to the same events without loading more scripts in the browser.

Nothing about your GA4 property changes: same measurement ID, same reports.

Before you start

  • A GA4 property and its measurement ID (G-…).
  • A web GTM container on your site.
  • A server GTM container running somewhere (a host such as TagLinc, or your own Google Cloud project), with its URL.
  • Ideally a subdomain of your site pointed at it, such as track.yourstore.com (see custom first-party tracking domains).

Step 1: The web container

  1. Open the Google tag (the GA4 configuration). Tag ID: your G-… measurement ID. Trigger: Initialization – All Pages.
  2. Under Configuration settings, add server_container_url with your tagging server's address, for example https://track.yourstore.com. No path, no trailing slash.
  3. For ecommerce, add a GA4 event tag: event name {{Event}}, Send ecommerce data from the data layer, fired by a custom event trigger for view_item, add_to_cart, begin_checkout, purchase and the rest. It inherits the server URL from the Google tag.
  4. Optional but worth it: load gtm.js itself from your tagging server too (the server container's web container client), so the GTM script is first-party as well.

Step 2: The server container

  1. Clients: the GA4 client is there by default. It claims requests to /g/collect and turns them into events.
  2. Tags: add a Google Analytics: GA4 tag. Leave the measurement ID empty to use the one in the incoming request. Trigger: Custom, Client Name equals GA4.
  3. Running Google Ads too? Add the Conversion Linker on the same trigger.
  4. Publish both containers. A server container that is not published does nothing, even if preview looks fine.

The GA4 client has a cookie and client ID setting with two choices: JavaScript managed (the usual _ga cookie, set in the browser) and Server managed (an FPID cookie that the server sets as HttpOnly).

Server managed only works when the tagging server is on your site's own domain. Google's documentation says the same: on a default domain the server "can only set Javascript cookies". We saw exactly this on our test store. Its server container was set to Server managed, but the store (taglinko.myshopify.com) sends to a tracking address on a different domain. The server answered with:

set-cookie: FPID=…; Max-Age=63072000; Domain=taglinko.myshopify.com; Path=/; Secure; HttpOnly

That cookie names the store's domain but comes from another one, so the browser rejects it. Nothing shows an error; the cookie just never exists.

Rule: use Server managed only when your tagging server runs on a subdomain of your site (track.yourstore.com) or the same origin. Otherwise keep JavaScript managed. TagLinc's ready-made server containers use JavaScript managed for this reason.

What we measured on the test store

One product page view and one add to cart, read from the browser and from the server container's own request log:

Request to the tracking domainStatusTime at the server
/gtm.js (first load)200560 ms
/gtm.js (cached on the server)20065 ms
/gtag/js200340 ms
/g/collect page_view200224 ms
/g/collect view_item200227 ms
/g/collect add_to_cart200248 ms

No request went to google-analytics.com from the browser: every GA4 hit carried the measurement ID and the consent state (gcs=G111) to the tracking domain, and the server sent it on.

How to check your own setup

  1. Browser: open developer tools → Network, filter by collect, reload. Every GA4 request should go to your tracking domain, none to google-analytics.com. A request still going to Google means a GA4 tag without the server URL (often a second, older GA4 tag or the store platform's own Google integration).
  2. Server preview: in the server container press Preview, then preview the web container. Each request should show Client: GA4 and the GA4 tag as fired.
  3. GA4: Admin → DebugView while previewing, or the Realtime report. Events arrive as usual.
  4. Your host's logs: TagLinc shows every request with its status in Event Logs. A 200 at the server and nothing in GA4 usually means the server's GA4 tag did not fire (trigger, or the container is not published).

Common problems

1
Double counting: the old GA4 tag (or a platform's built-in Google channel) still sends straight to Google next to the new one. Keep one GA4 path.
2
Nothing in GA4: the server container is not published, or the GA4 tag's trigger does not match the GA4 client.
3
Preview works, live does not: one of the two containers was published without the change.
4
Users jump after the switch: a change of client ID (for example moving to Server managed on the wrong domain, or a new cookie name) makes returning visitors look new. Change one thing at a time and watch Realtime.
5
Consent: the browser still decides. If the visitor declined, GA4 sends cookieless pings or nothing, and the server forwards only that. See Consent Mode v2 with server-side GTM.

When it is not worth it

A small site with few ad-blocker users and no paid ads gets little from moving GA4 alone. The case gets strong when you also send conversions to Meta, Google Ads or TikTok from the same server, or when Safari's short cookie life is breaking your returning-visitor and attribution numbers.

Not sure your tracking is right?

We check your setup for free and send you what to fix.

Free tracking audit

FAQ

No. Keep your property and measurement ID; only the route the data takes changes.

Not if you leave it empty: it uses the ID from the incoming request. Fill it only to send to a different property.

Yes, events still flow, but with JavaScript managed cookies only. Your own subdomain is what gives you server-set, longer-lived cookies.

Fewer will, because the requests go to your own domain. Blockers that work by script name or path can still catch some; loading gtm.js from a custom path helps.

Sources

MH
Founder of TagLinc. Mahmudul builds the TagLinc platform, writes its documentation and answers the support email himself.