GA4 / GTAG
Data Capture Script Alternatives
Markus Baersch
Why Not GTAG.JS?
gtag.js
some issues
Source: in client-side setup likely to
be blocked by modern browsers
Heavy: does is all: GA, Ads, Optimize,
Badges and whatever
Complexity: Much stuff you might
not want
Control: let me define what is
“engaged”!
Consent: Consent Mode is a joke!
What to use (when running your own
endpoint for more than just GA4)?
gtag.js
… is odd!
Session Handling & More:
● control over “first_visit” and
“session_start”
â—Ź browser knows what is a
conversion, a referral exclusion…
â—Ź no way to hide your
measurement id
● much “serverside-stuff” has to be
handled by the browser
gtag.js
GTM light?
● Google Tag: “centrally manage
settings without additional code”
â—Ź modelled conversions
everywhere
googlemarketinglive.com/americas/
● just “sending hits” is not enough
(for GA4)
â—Ź GA4 Measurement Protocol is
not a full replacement
â—Ź additional tasks: knowing goals,
send created events, track time…
â—Ź event batching
● ssGTM “sendPixelFromBrowser”
â—Ź mocking Consent Mode
â—Ź sending enough data to feed
GA4 without consent: possible?
gtag.js
why replacing it is hard
⛪
🙏?
(Potential) Alternatives
GA4 Destination: might be one of the
few official partners (soon?)
Everything in place: does have own
session start markers. Utag.data seems
a good fit
Anyone tried this already (without
bundling gtag in the browser)?
Tealium
iQ Standard fits?
Or EventStream?
Seems to have all data: there are
timestamps, timings, hit numbers…
Tagging: relies either on HTML
attributes or events sent via JS
Anyone tried this one maybe? ;)
https://github.com/elbwalker/walker.js
elbwalker
open source event tracker
You would have to steal it: not open
source
GA4 connection “unofficial”: might
break in the future
Not very lightweight: >40kB
first hand experiences here?
https://www.jentis.com/
The JENTIS
approach
alternative capturing indeed
DIY
individual tracking script
â—Ź minimal footprint, no
dependencies
â—Ź fallback for sendbeacon()
â—Ź collect minimal dimensions
â—Ź re-use existing dataLayer
â—Ź use fingerprint or cookie
â—Ź enhanced tracking if consent:
â—‹ session handling
â—‹ returning visitors
â—‹ more dimensions
â—Ź use (obfuscated) POST
â—Ź quite hard (if only client-side)
Example
Loggy -> Snoop Logg / Luke Logbridge -> log2self
History
started as a simple replacement for analytics.js
5+ years ago
works from the browser only, but needs an
endpoint that knows the format
Used to forward events to GA, Piwik PRO,
Matomo and a few others
Worked without a “client-side session” well
before implementing GA4
one of the older ones:
https://gist.github.com/mbaersch/34af06d1336f8
78ea10f3f7b0e49d45c
evolving code grows ;)
send consent as payload
add an event id to avoid
deduplication problems in
“other systems” ;)
client-side timestamps are fine,
but use your own endpoint to
create new ones
code suddenly needs some
“initialisation”
More Dimensions
collect additional info with
consent only
(and throw out some stuff in
your endpoint as well)
remember: resolution,
(language), color depth & co
are all attributes that you
actively “read” from the
visitor´s device
Be Nice!
Session Handling
GA4 wants session handling
only active if consent is present
uses localStorage / sessionStorage -
which is only possible on a single
domain AND host
Sending Stuff
Try beacons, then AJAX, then
an image pixel as last fallback
…and make sure that your
endpoint looks for get
parameters.
and yes: use guard clauses
instead of all that else stuff if
you like ;)
Endpoint
FP endpoint for flexible data
handling
optionally use separate session,
timestamps, identifier
1:n tracking
debugging with headers
GA4: refer to
https://www.thyngster.com/ga4-
measurement-protocol-
cheatsheet/ for a parameter
reference
(would have saved a lot of time for me)
Endpoint (2)
Use ssGTM and translate own format to GTM events
or build your own in Node, PHP or whatever
Remember: CNAME is not an option
cloud edge endpoints are a promising alternative
Final Tipps
send base64 coded payload
… or even build your own
coding (or just do rot13 :))
Keeping your own format
makes you (somewhat)
independent
remember: a tracking server
has to handle a lot of stuff. Do
not use your website server
(unless you have low traffic
like me ;))
Done!
Questions?
or feedback?
what was great, what not so
much? Let me know!
E-Book
main focus on ssGTM
markus-baersch.de/gtmbook

GA4/GTAG Data Capture Alternatives

  • 1.
    GA4 / GTAG DataCapture Script Alternatives Markus Baersch
  • 2.
  • 3.
    gtag.js some issues Source: inclient-side setup likely to be blocked by modern browsers Heavy: does is all: GA, Ads, Optimize, Badges and whatever Complexity: Much stuff you might not want Control: let me define what is “engaged”! Consent: Consent Mode is a joke! What to use (when running your own endpoint for more than just GA4)?
  • 4.
    gtag.js … is odd! SessionHandling & More: ● control over “first_visit” and “session_start” ● browser knows what is a conversion, a referral exclusion… ● no way to hide your measurement id ● much “serverside-stuff” has to be handled by the browser
  • 5.
    gtag.js GTM light? ● GoogleTag: “centrally manage settings without additional code” ● modelled conversions everywhere googlemarketinglive.com/americas/
  • 6.
    ● just “sendinghits” is not enough (for GA4) ● GA4 Measurement Protocol is not a full replacement ● additional tasks: knowing goals, send created events, track time… ● event batching ● ssGTM “sendPixelFromBrowser” ● mocking Consent Mode ● sending enough data to feed GA4 without consent: possible? gtag.js why replacing it is hard
  • 7.
  • 8.
  • 9.
    GA4 Destination: mightbe one of the few official partners (soon?) Everything in place: does have own session start markers. Utag.data seems a good fit Anyone tried this already (without bundling gtag in the browser)? Tealium iQ Standard fits? Or EventStream?
  • 10.
    Seems to haveall data: there are timestamps, timings, hit numbers… Tagging: relies either on HTML attributes or events sent via JS Anyone tried this one maybe? ;) https://github.com/elbwalker/walker.js elbwalker open source event tracker
  • 11.
    You would haveto steal it: not open source GA4 connection “unofficial”: might break in the future Not very lightweight: >40kB first hand experiences here? https://www.jentis.com/ The JENTIS approach alternative capturing indeed
  • 12.
    DIY individual tracking script â—Źminimal footprint, no dependencies â—Ź fallback for sendbeacon() â—Ź collect minimal dimensions â—Ź re-use existing dataLayer â—Ź use fingerprint or cookie â—Ź enhanced tracking if consent: â—‹ session handling â—‹ returning visitors â—‹ more dimensions â—Ź use (obfuscated) POST â—Ź quite hard (if only client-side)
  • 13.
    Example Loggy -> SnoopLogg / Luke Logbridge -> log2self
  • 14.
    History started as asimple replacement for analytics.js 5+ years ago works from the browser only, but needs an endpoint that knows the format Used to forward events to GA, Piwik PRO, Matomo and a few others Worked without a “client-side session” well before implementing GA4 one of the older ones: https://gist.github.com/mbaersch/34af06d1336f8 78ea10f3f7b0e49d45c
  • 15.
    evolving code grows;) send consent as payload add an event id to avoid deduplication problems in “other systems” ;) client-side timestamps are fine, but use your own endpoint to create new ones code suddenly needs some “initialisation” More Dimensions
  • 16.
    collect additional infowith consent only (and throw out some stuff in your endpoint as well) remember: resolution, (language), color depth & co are all attributes that you actively “read” from the visitor´s device Be Nice!
  • 17.
    Session Handling GA4 wantssession handling only active if consent is present uses localStorage / sessionStorage - which is only possible on a single domain AND host
  • 18.
    Sending Stuff Try beacons,then AJAX, then an image pixel as last fallback …and make sure that your endpoint looks for get parameters. and yes: use guard clauses instead of all that else stuff if you like ;)
  • 19.
    Endpoint FP endpoint forflexible data handling optionally use separate session, timestamps, identifier 1:n tracking debugging with headers GA4: refer to https://www.thyngster.com/ga4- measurement-protocol- cheatsheet/ for a parameter reference (would have saved a lot of time for me)
  • 20.
    Endpoint (2) Use ssGTMand translate own format to GTM events or build your own in Node, PHP or whatever Remember: CNAME is not an option cloud edge endpoints are a promising alternative
  • 21.
    Final Tipps send base64coded payload … or even build your own coding (or just do rot13 :)) Keeping your own format makes you (somewhat) independent remember: a tracking server has to handle a lot of stuff. Do not use your website server (unless you have low traffic like me ;))
  • 22.
    Done! Questions? or feedback? what wasgreat, what not so much? Let me know!
  • 23.
    E-Book main focus onssGTM markus-baersch.de/gtmbook

Editor's Notes

  • #2 Some kind of a “gtag.js - rant”: Is gtag.js really the best way to collect events in the browser? Why is gtag.js in general odd and what are the features that are used to feed GA4 with data? We will take a look at what gtag.js does, what alternative ways for data capturing already exist and how an individual replacement can be built.
  • #3 https://www.flaticon.com/
  • #13 David Vallejo did this for client-side tracking as well! ;)