google tag manager scripts exploration
published 2026-04-13 · updated 2026-08-25 · gtm sgtm · [repo]
GTM scripts exploration is a personal research project focused on understanding how Google Tag Manager works under the hood. It combines prettified container code with structured Markdown documentation to map runtime behavior. The project tracks changes in GTM scripts (gtm.js and server-side container snapshots) over time.
This article gives a concise overview of the repository.
Why this project?
Official documentation explains what to configure, but rarely how things work internally. The interaction between consent, the dataLayer, cookies, linker parameters, and requests can be difficult to trace. Especially for server-side tagging.
This project does not claim to reverse-engineer hidden logic. Instead, it documents structure, annotates key components, and follows execution flow, so you can connect GTM concepts to the code that implements them.
Repository structure
Dated snapshots live in detailed_explanation/containers/<M.YYYY>/ (latest: 8.2026, previous: 4.2026). Each new folder has the script plus CHANGES.md.
client-side-gtm/
gtm.js— prettified export of a web container, stored per snapshot next toCHANGES.md(latest:containers/8.2026/gtm.jsandCHANGES.md). The main artifact for the browser track.gtm_summary.mdandgtm_summary_detail.md— narrative walkthroughs of the container (resource loading, tag order, and per-tag behavior).detailed_explanation/— one Markdown file per major built-in tag type (for example Google Tag, GA4, Google Ads, Conversion Linker), with references to line ranges ingtm.jsso you can jump between prose and source.README.md— index and links into the client-side docs (the upstream README points readers atgtm_summary.mdas the main overview).
server-side-gtm/
server_container.js— large, structured representation of a server container bundle, stored per snapshot next toCHANGES.md(latest:containers/8.2026/server_container.jsandCHANGES.md).server_bootstrap.js— Node.js entry that loads and refreshes the container and starts the HTTP server.google_ads_tags_summary.mdandgoogle_analytics_tags-summary.md— focused summaries for those tag families.detailed_explanation/— deeper dives (clients, tags, modules, consent, cookies, enhanced conversions, encryption such as HPKE, compression, and related pieces), tied back to locations in the bundle.docker-original-image/— reference Dockerfile, scripts, and dependencies aligned with Google’s sGTM deployment shape. Useful for context, not as a production recipe.README.md— howserver_container.jsis organized, line maps, and pointers to the client/tag notes.
What this project is not
- It is not a replacement for GTM or official documentation.
- It does not guarantee accuracy across every GTM release; compiled output changes over time. Dated folders and
CHANGES.mdfiles are how those shifts are recorded. - It is not intended for direct production use.
The material may be incomplete or incorrect and is provided as is, without liability. Always validate implementations using official documentation and your own testing, especially for compliance or business-critical tracking.