| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A CLI toolkit for Google Tag Manager. Terraform-style developer experience: predictable, read-only by default, plan before apply.
gtm-diff diff before.json after.jsonGTM containers are routinely changed by several people at once, often by non-engineers, with no review. A bad tag change can silently break site analytics for weeks. gtm-diff brings code review, CI, and versioned change management to GTM.
Phased delivery. v0.1 ships first. v0.2 (plan) and v0.3 (apply) land only after the diff engine has been used in anger.
| Version | Command | Writes to GTM? | Status |
|---|---|---|---|
| v0.1 | gtm-diff diff <before> <after> | no | complete, not yet published |
| v0.2 | gtm-diff plan --source <a> --target <b> | no — emits a plan file | planned |
| v0.3 | gtm-diff apply --plan plan.json | yes, with --apply and explicit confirms | planned |
Not on npm yet. Build it from source:
git clone https://github.com/arcbaslow/gtm-diff
cd gtm-diff
npm ci
npm run build
npm link # puts `gtm-diff` on your PATHOr run it without linking:
npm run dev -- diff before.json after.jsonNode.js >=20.0.0 required.
Once the first release is cut, npm install -g gtm-diff and npx gtm-diff will work as you'd expect.
Compare two GTM container JSON exports produced by Admin → Export Container in the GTM UI (or by the GTM API).
gtm-diff diff before.json after.json
gtm-diff diff before.json after.json --format markdown --output diff.md
gtm-diff diff before.json after.json --format html --output diff.html
gtm-diff diff before.json after.json --exit-code # for CI| Flag | Description |
|---|---|
| -f, --format | console (default), markdown, or html |
| -o, --output | Write the report to a file instead of stdout |
| --no-color | Disable ANSI colors in the console output |
| --exit-code | Exit with code 1 if any differences are found |
Entities are matched by (type, name), not by GTM-assigned ID, so the diff is stable across exports from different workspaces or environments. Before comparing, each entity is normalized:
If a trigger, folder, or tag is renamed, the diff shows one removed and one added entry — same as Git. If you want to track a rename, do it as a deliberate change.
# .github/workflows/gtm-diff.yml
name: GTM diff
on:
pull_request:
paths: ['gtm/**/*.json']
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: actions/setup-node@v4
with: { node-version: 20 }
- name: Produce diff
# Swap for `npx gtm-diff` once the package is published.
run: |
git show origin/${{ github.base_ref }}:gtm/container.json > /tmp/before.json
npx github:arcbaslow/gtm-diff diff /tmp/before.json gtm/container.json \
--format markdown --output diff.md
- name: Post as PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
path: diff.mdgtm-diff plan and gtm-diff apply are intentionally not yet available. Shipping apply without safety rails could wipe production tracking for someone's company. Read the full reasoning in the commit history and the Phased scope table.
When they ship, apply will:
The diff engine is exposed as a library:
import { loadGtmExport, diffExports, renderMarkdown } from 'gtm-diff';
const before = await loadGtmExport('before.json');
const after = await loadGtmExport('after.json');
const diff = diffExports(before, after);
console.log(renderMarkdown(diff));npm install
npm run dev -- diff test/fixtures/minimal-before.json test/fixtures/minimal-after.json
npm test
npm run typecheck
npm run lintMIT © Dilshat Rakhimov
Part of a set of marketing-measurement toolkits:
Built and maintained by Good Labs.
| Back | FazBrowse Home | New Git URL |