Custom GTM Client Templates
(and why it is so hard to replace gtag / GA4)
Markus Baersch
What is a client in ssGTM?
ssGTM
“Receiving Thingies” in ssGTM
Events
key1: value1
key2: value2
key3: value3
…
Tags
Tag
Tag
Tag
Clients
Client
Clien
t
Client
/endpoint?param1=x&param2=y…
Common client tasks
Respond
3
â—Ź process (response) data from tags
â—Ź send server response (usually)
“Decouple” tags
from raw requests
2
â—Ź create event data
â—Ź run container to trigger tags
Receive requests
1
â—Ź different endpoints
â—Ź or same endpoint and different
priority (first to “claim” wins)
How “clients” got their name And finally: how
should we call
those receiving
thingies? worker
!
listener
!
endpoint
!
collector!
sensor!
receiver
!
event
processor!
client
đź’©
Senior dev had dark mode and could speak in Courier
New. So unfortunately, he took the jackpot… :(
Clients in ssGTM
Clients in ssGTM
Event Data: What tags need to work
Comparing GA4 requests
Q: Will a GA4 request be the same after passing ssGTM?
https://www.diffchecker.com/R1z4xmC9/
A: No
Q: What if GA4 adds new parameters?
Everything ends up in X-Files Fields ;)
Building client templates
Building a custom client is easy!
https://developers.google.com/tag-platform/tag-manager/server-side/api
Building a custom client is easy!
Forwarding all parameters as event data? Easy!
data.example.com/param_demo?
event_name=my_event&val1=1&foo=bar&value=42
&currency=EUR&item_id=2&item_name=widget
Custom client use cases
Analytics / Data
Snowplow
Piwik PRO
…
Proxy
Tagless Re
quest Prox
y
APIs
“Cloud
Functions”
Preflight Requ
ests
Alternative
(GA4)
clients
Serve
resources
Static or
dynamic
GA4 requests / client alternatives?
Building a custom GA4 client is (still) easy!
Replacing GA4 requests is not easy
GA4 Measurement
Protocol
Needs help by a web
session and drops weights
on own foot
Universal Analytics
Measurement
Protocol
Goes all the way
Replacing GA4 requests is not easy
â—Ź browser controls everything!
â—‹ e.g. start, count, end of session
â—Ź parameters constantly change!
â—Ź Consent Mode
-> running GA4 on a non-GA4 request stream is
hard!
GA4 event data…
… is quite different
Options
â—Ź live with some constraints
â—Ź do not expect data suitable for advertising
â—Ź mimic gtag in the browser and use GA4 client
â—Ź use alternatives like walker OS, Stape data
tag
â—Ź do not use GA4 at all ;)
-> use custom clients for other tools or tasks!
Example: walker.js in, Piwik PRO out
Example: walker.js in, Piwik PRO out
Server-Side
Custom client tips
Good to know:
âž” always return a response (there
is more than a status code)
âž” running the container is
optional
âž” clients can use the same APIs as
tags
âž” requests can contain multiple
events
Server-Side
Custom client tips
When more clients are used:
âž” check your trigger conditions
➔ “all events” or “all pages”
triggers are no longer your
friend
âž” use transformations whenever
clients and / or tags do not
allow event redaction
Done ;)
Thank you! :)
markus-baersch.de/
slideshare
markus-baersch.de/
podcast
markus-baersch.de/
youtube
Build!
markus-baersch.de/gtmb
ook

Custom Server-Side Google Tag Manager Client Templates

Editor's Notes

  • #3 …or POST Payloads GA4 = (mostly): extract params, build events and then build the same params from events again. WHAT HAPPENS IF THERE ARE UNKNOWN PARAMS?
  • #8 Not in Community Gallery Search for client templates on GitHub
  • #9 Most tags rely on the GA4 event model
  • #12 Explain priority
  • #13 Explain priority
  • #15 Explain priority https://data.atomkraftwerke24.de/helloworld?foo=bar
  • #17 Or read and process headers or body (like POST payloads), get external data from APIs or Firestore A tag could basically do the same… https://data.atomkraftwerke24.de/param_demo?event_name=my_event&val1=1&foo=bar&value=42&currency=EUR
  • #18 Or read and process headers or body (like POST payloads), get external data from APIs or Firestore access GA4 request data with a single sandbox API call
  • #21 Explain priority https://data.atomkraftwerke24.de/g/collect?v=2&tid=G-WZPST6702Z&gtm=45je4930v883834853z8836065292za200zb836065292&_p=1725532707183&_dbg=1&gcs=G111&gcd=13t3t3t2t5l1&npa=0&dma_cps=syphamo&dma=1&dma_mbsl=2&tag_exp=0&cid=1376843275.1725017924&ecid=2091520439&ul=de-de&sr=1920x1080&ur=DE-NW&uaa=x86&uab=64&uafvl=Chromium%3B128.0.6613.119%7CNot%253BA%253DBrand%3B24.0.0.0%7CGoogle%2520Chrome%3B128.0.6613.119&uamb=0&uam=&uap=Windows&uapv=15.0.0&uaw=0&are=1&frm=0&pscdl=noapi&sst.rnd=1489458292.1725532709&sst.etld=google.de&sst.gcsub=region1&sst.tft=1725532707183&sst.ude=0&_s=1&dl=https%3A%2F%2Fatomkraftwerke24.de%2F&sid=1725532115&sct=3&seg=1&dr=https%3A%2F%2Fatomkraftwerke24.de%2Fshop%2F&dt=atomkraftwerke24.de%20%E2%80%93%20Ein%20Testshop.%20Nicht%20ernst%20gemeint%2C%20aber%20n%C3%BCtzlich&en=page_view&ep.method=something&ep.event_id=1725532708358.745169.183&_et=1&tfd=2638&richsstsse&foo=bar
  • #26 Luke Logbridge or other simple formats are perfectly sufficient for tools like Plausible, Matomo, Piwik PRO. And it used to be okay for UA, too :(
  • #29 think of GA4 client: sets cookies. Cookie Monster and several tag templates do the same
  • #32 markus-baersch.de/bsky