In this category Integrations

Integrations

Server-side tracking with Stape and Google Tag Manager

Send Google Analytics data through your online shop's own domain with Stape and a Google Tag Manager server container. What it gives you, what it does not, and the whole setup step by step.

9 min read

On this page

With server-side tracking your online shop no longer sends data directly to Google. Instead, the visitor's browser sends data to a subdomain of your shop, e.g. abc123.minshop.dk. Behind that subdomain a Google Tag Manager server container runs at Stape, and it passes the data on to Google Analytics.

We have set it up in our own test shop and measured what it gives. This guide follows that setup, including the places where Google and Stape did not do the right thing by themselves. It covers Google Analytics 4 with our Google Analytics code.

What it gives, and what it does not

It gives you:

  • Data goes through your own domain. The browser does not talk to google-analytics.com or googletagmanager.com. Programs and networks that block Google's domains therefore do not block your data. We tested this by blocking Google's domains in the browser: every event still arrived.
  • Control on the server. You decide what is passed on to Google. For example, the Google Analytics tag in the server container can remove the visitor's IP address before the data is passed on.

It does not give you:

  • More data from those who say no. Consent works exactly as before. If the visitor says no, the code sends only the anonymous, cookieless measurements that Google Consent Mode allows.
  • Data from uBlock Origin. The most widely used ad blocker also blocks Google's code and measurements on your own subdomain, because it recognises the addresses. We measured this with uBlock Origin Lite and its default lists. The same probably applies to Brave.
  • Longer cookies in Safari. Safari keeps the Google Analytics cookie for 7 days at most, also with server-side tracking.

There is also a risk: if the subdomain is down, or your plan at Stape is paused, no data reaches Google Analytics at all.

Stape has a feature that also gets past uBlock (Custom Loader with "Enhanced ad blocker protection"). We tested it and chose not to use it, because it makes the setup considerably more complicated. It is not part of this guide.

What it costs

Stape charges by the number of requests to your server. In our test each page view gave 2 to 6 requests (Google's code, the measurements and a helper file).

  • Free: 10,000 requests a month. It is only for trying out the setup. When the limit is reached, Stape switches the container off until you upgrade.
  • Pro: 500,000 requests a month for €20 a month (in November 2026). That covers most online shops.

Turn on automatic upgrading (see step 3). Otherwise Stape pauses the container once you have used 10% more than your plan, and you lose data. See Stape's prices (opens in a new tab).

Stape processes data on behalf of your visitors. Choose a server in the EU, and keep Stape's data processing agreement (see step 3). Stape's log keeps each measurement with the visitor's IP address and browser for 3 days on Pro. Add Stape to your privacy policy as a data processor.

What you need

Follow the steps in the order given. The server container in Tag Manager must exist before you create the container at Stape.

1. Create a server container in Google Tag Manager

  1. Go to Google Tag Manager (opens in a new tab), and create an account if you do not have one.
  2. Click Create container under your account.
  3. Enter a name, e.g. "minshop.dk - server", and choose Server under Target platform. Click Create.

The Create container form in Google Tag Manager with the name minshop.dk - server and Server chosen (opens a larger image)

  1. Choose Manually provision tagging server in the window that appears.
  2. Copy the text under Your container config is:. You will need it at Stape. Leave Tag Manager open.

The container config field in Google Tag Manager (opens a larger image)

2. Create a container at Stape

  1. Create an account at stape.io (opens in a new tab), and choose EU under Customer data storage location. Your data and your account at Stape are then kept in the EU.
  2. Click Create sGTM container.
  3. Enter your shop's name under Container name, choose Manually under Container configuration, and paste the text from Tag Manager into the field.
  4. Choose a server in the EU under Server location, e.g. EU North (Netherlands). It cannot be changed later.
  5. Create the container.

Stape's form for a new container with a name, Manually, the container config field and Server location EU North (Netherlands) (opens a larger image)

Once the container is created, you see it under Settings with the server location and the ID it belongs to in Tag Manager.

The Container settings card at Stape with Container config and Server location marked (opens a larger image)

3. Choose a plan, automatic upgrading and the data processing agreement

  1. Choose Pro under Change plan on the container.
  2. Turn on Upgrade container to the next tier automatically on the Subscription tab. Then measuring continues if a campaign brings more visits than the plan covers.

The setting Upgrade container to the next tier automatically under Subscription at Stape (opens a larger image)

  1. Read Stape's data processing agreement for the EU (opens in a new tab). It applies automatically once you have accepted Stape's terms when creating the account. Keep it with your other data processing agreements.

4. Add your subdomain

The subdomain is the address the browser sends data to. Use a name that does not give away what it is. Stape advises against words such as ad, gtm, tracking, analytics and stape, because ad blockers look for them. Stape suggests a random name itself, and you can simply use that.

  1. Go to Domains (Tagging Server URLs) on the container, and click Add new.
  2. Enter the subdomain, e.g. abc123.minshop.dk, leave CDN switched off, and choose Manually under How to connect. Click Next.
  3. Stape now shows the DNS record you need to create: a CNAME with the subdomain as the name and Stape's address as the value.

The DNS record from Stape: Type CNAME, Host with the subdomain and Value eus.stape.net (opens a larger image)

  1. Create the record wherever your domain has its DNS. If your DNS is with us, see Name service (DNS).
  2. Click Verify at Stape. The status changes to Ready when Stape has found the record and made a certificate. For us it took 7 minutes. Stape says it can take up to 72 hours. You see the status by clicking ... next to the subdomain and choosing View details.

The subdomain at Stape with the status Ready and the DNS record (opens a larger image)

5. Set up the server container in Tag Manager

Go back to your server container in Tag Manager.

Cookies: JavaScript Managed

  1. Click Clients, and open GA4.
  2. Click More Settings, and choose JavaScript Managed under Cookies and Client Identification. Click Save.

The GA4 client in Google Tag Manager with Cookies and Client Identification set to JavaScript Managed (opens a larger image)

The default is Server Managed. The server then sets its own cookie, which a cookie banner cannot delete. If a visitor withdraws their consent, that cookie stays. With JavaScript Managed the cookie banner deletes all of it.

Google's code from your own domain

  1. Click Clients and New, and choose Google Tag Manager: Web Container.
  2. Click Add Container ID, and enter your measurement ID from Google Analytics (it starts with G-).
  3. Untick Enable region-specific settings. Otherwise the client cannot be saved.
  4. Give the client a name, e.g. "Google scripts (gtag.js)", and click Save.

The client of the type Google Tag Manager: Web Container with your measurement ID under Allowed Container IDs (opens a larger image)

Pass the data on to Google Analytics

  1. Click Triggers and New. Choose Custom and Some Events.
  2. Choose the variable Client Name (under Choose Built-In Variable if it is not in the list), equals and enter GA4. Give the trigger a name, e.g. "All GA4 events", and click Save.

The All GA4 events trigger of the type Custom with the condition Client Name equals GA4 (opens a larger image)

  1. Click Tags and New. Choose Google Analytics and Google Analytics: GA4. Leave the fields as they are.
  2. Choose the trigger from before under Triggering, give the tag a name, e.g. "GA4 - send to Google Analytics", and click Save.

The tag in the server container with the tag type Google Analytics: GA4 and the trigger All GA4 events (opens a larger image)

The subdomain and publishing

  1. Click Admin and Container Settings. Click Add URL under Server container URLs, enter https:// and your subdomain, and click Save.

Container Settings in Google Tag Manager with the subdomain under Server container URLs (opens a larger image)

  1. Click Submit, enter a name for the version, and click Publish.

The Submit Changes page in Google Tag Manager with Publish and Create Version, a version name and the Publish button (opens a larger image)

It can take up to a quarter of an hour before Stape uses the new version.

6. Tell Google Analytics about the subdomain

Google has started to "upgrade" Google tags to a Tag Manager container itself. If your tag has been upgraded, Google ignores the server address that the code in your online shop sends along, and data still goes directly to Google. This happened in our test shop, while an older tag in our demo shop worked without changes. This is how you see whether it applies to your tag, and fix it:

  1. Go to Admin > Data streams in Google Analytics, and click your web stream.
  2. Click Configure tag settings under Google tag further down the page. The panel opens.
  3. If it says "Your Google tag has been upgraded to a Tag Manager container", click Tags and open Google Analytics G-….

The Google tag settings with the message that the tag has been upgraded, and the tag Google Analytics G-… on the Tags tab (opens a larger image)

  1. Click Tag Configuration, and click Add parameter under Configuration settings. Enter server_container_url in the first field and https:// plus your subdomain in the second. Click Save.

The tag Google Analytics G-… with the parameter server_container_url and the subdomain as its value (opens a larger image)

  1. Click Submit and Publish.

If it says nothing about an upgrade, you do not need to do anything here. Google then uses the server address from the code in step 7.

7. Add the server address to the code in your online shop

  1. Open the Google Analytics guide, and create the code again with your measurement ID. Enter your subdomain in the Server address field, e.g. abc123.minshop.dk.
  2. Replace the code in your integration under Integration > Custom Integration with the new code, and save.

The code now loads Google's code from your subdomain and sends every measurement there. Consent from your cookie banner works as before.

8. Check that it works

  1. Open your online shop in a private window, and say yes to cookies.
  2. Go to the Logs tab on the container at Stape. Here you should see new lines with /g/collect and events such as PageView.

The Logs tab at Stape with incoming measurements from GA4, one PageView marked (opens a larger image)

  1. Open Reports > Realtime overview in Google Analytics. Your visit should appear there after a minute or two.

We also tested that consent comes along: before an answer and after a no, only anonymous measurements without cookies arrive, and if the visitor withdraws their yes, the Google cookies disappear.

Good to know

  • Facebook and Google Ads: Leave the Facebook Conversions API in the online shop and the built-in Google Ads conversion as they are. Do not also set up a Meta tag or a Google Ads tag in the server container, because then everything is counted twice.
  • Cookies for the whole domain: The shop's cookies that apply to the whole domain, e.g. the basket's ID, are also sent to the subdomain. Stape's log does not keep them.
  • Stape's other features: Cookie Keeper only works together with Custom Loader, which we chose not to use. Bot Detection marks requests from bots, but only blocks at a very high score. We have not used them.
  • If you change your mind: Create the code again without a server address, and remove server_container_url from the Google tag if you added it there. Otherwise data still goes to the subdomain.