Skip to content

Send GA4 from web GTM through your server container

Your server container is running, but nothing sends data to it yet. In this lesson you create a GA4 property, add a Google tag and GA4 Event tags to your web container, and tell them to send every hit to your own subdomain instead of Google. GA4 hits then go to k7q2x.example.com instead of Google, and the server container decides where the data goes next. The GTM and gtag.js scripts themselves still load from googletagmanager.com unless you serve them from your own domain (lesson 8).

Intermediate 12 min read Version 1.3, updated October 3, 2026

What you will learn

  • Create a GA4 property and web data stream and find the Measurement ID.
  • Add a Google tag with server_container_url in the web container.
  • Send custom and ecommerce events with GA4 Event tags.
  • Confirm in DevTools that hits go to your subdomain.

Before you start

  • A published web container on your site (lesson 1).
  • A server container that answers on your subdomain, for example k7q2x.example.com (lesson 2).
  • Editor access to a Google Analytics account.

01 Create the GA4 property and web stream

Skip this section if you already have a GA4 property. You only need its Measurement ID.

  1. 1 Open analytics.google.com, go to Admin and click Create, then Property.
  2. 2 Enter a property name, your reporting time zone and currency, then finish the business details.
  3. 3 When asked to start collecting data, choose Web, enter your website URL and a stream name, and click Create stream.
  4. 4 Copy the Measurement ID from the stream details. It looks like G-XXXXXXXXXX.

02 Add the Google tag with your server URL

The Google tag loads GA4 on the page and sends the page_view. One setting, server_container_url, changes where its hits go.

How does your site load GA4?

  1. 1 In your web container go to Tags, click New and choose Google tag as the tag type.
  2. 2 Paste your Measurement ID into Tag ID.
  3. 3
    Under Configuration settings, add a row with this parameter and value.
    Configuration parameter
    server_container_url
    Value
    https://k7q2x.example.com
  4. 4 Set the trigger to Initialization - All Pages (or All Pages), name the tag and save.

Initialization - All Pages fires before other tags, so events that fire early already know where to send their data.

Use exactly the URL of your server container: https://, no path and no trailing slash.

03 Send events with GA4 Event tags

Page views and enhanced measurement events (scrolls, outbound clicks, site search, file downloads) come from the Google tag automatically. Your own events, such as sign-ups and purchases, need a Google Analytics: GA4 Event tag. Reuse the sign_up trigger from lesson 1:

  1. 1 Create a tag of type Google Analytics: GA4 Event.
  2. 2 Set Measurement ID to G-XXXXXXXXXX (your ID). The event goes through the Google tag with the same ID, including its server URL.
  3. 3 Set Event Name to sign_up. Under Event Parameters add method with the Data Layer Variable you created earlier.
  4. 4 Select the Custom Event trigger sign_up and save.
Ecommerce: send purchases

For ecommerce, your site pushes the purchase details in the ecommerce object that GA4 expects. Clear the previous ecommerce object first, as in this example.

JavaScript
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: 'purchase',
  ecommerce: {
    transaction_id: 'T-10293',
    value: 129.90,
    currency: 'EUR',
    items: [{ item_id: 'SKU-1', item_name: 'Shoes', price: 129.90, quantity: 1 }]
  }
});
  1. 1 Create a Custom Event trigger for purchase.
  2. 2 Create a Google Analytics: GA4 Event tag with Event Name purchase.
  3. 3 Open More Settings, then Ecommerce, tick Send Ecommerce data and choose Data Layer as the Data source.
  4. 4 Attach the purchase trigger and save.

04 What changes in the browser

Without a server URL, GA4 sends hits to Google hosts such as region1.google-analytics.com or analytics.google.com. With it, the same hits go to your subdomain on the /g/collect path:

https://k7q2x.example.com/g/collect?v=2&tid=G-XXXXXXXXXX&en=page_view&...
  • The request stays on your own domain, so it is first-party for the browser.
  • Fewer blockers match it, because it no longer goes to a known analytics domain. Blockers that match the /g/collect path can still catch it: Request Proxy in lesson 8 covers that.
  • The server container sees every GA4 hit before GA4 does, which is where you can filter or enrich data later.

05 Verify and publish

  1. 1 Click Preview in the web container and connect to your site. The Google tag should fire on Initialization and the GA4 Event tags on their events.
  2. 2 In the site window open DevTools, go to the Network tab and filter by collect.
  3. 3 Reload the page. You should see requests to https://k7q2x.example.com/g/collect with status 200 or 204, and none to google-analytics.com or analytics.google.com.
  4. 4 When everything looks right, click Submit and publish the web container.
  • No hard-coded gtag.js snippet for the same ID is left on the site.
  • The Google tag has server_container_url set to your subdomain.
  • /g/collect requests go to k7q2x.example.com.
  • The server container Preview shows incoming requests (the debugging lesson explains how to read it).

Frequently asked questions

Do I also need a Google tag for Google Ads?

Not for this lesson. GA4 hits are enough to feed the server container, and server-side tags for other vendors can reuse the same incoming data.

The requests still go to google-analytics.com. What is wrong?

Usually the change is not published yet, another Google tag or a hard-coded gtag.js snippet for the same ID loads without the setting, or the parameter name has a typo. It must be exactly server_container_url.

Ready to put it into practice?

Deploy a server GTM container on your own domain in a few minutes. The Free plan needs no card.

Create a free account