# Worked example: Acme Store (fictional)

Everything here is fictional and runs from the skill folder with no network access. The numbers below were produced by script 0.3.0 and are pinned in [../assets/regression-expected.json](../assets/regression-expected.json), so `node scripts/check-regression.mjs` fails if they drift. In a real audit, work in an audit folder in the user's project and call the scripts by their path in the skill folder.

## Files

- [../assets/example-acme-export.json](../assets/example-acme-export.json): UI export of "Acme Store - web", GTM-XXXXXXX, live version 42 "Spring checkout release", exported 2026-10-31 09:12.
- [../assets/example-acme-stack.md](../assets/example-acme-stack.md): the `stack.md` the agent reads first. Expected IDs G-XXXXXXXXXX, AW-123456789 and Meta pixel 1234567890123456; retired Google Ads 987654321, UA-XXXXXXX-1 and Hotjar site 1234567; purchases complete on www.example.com and shop.example.com; the server container sends Meta Conversions API Purchase and Lead with the data layer `event_id`; key events purchase and generate_lead; the GA4 Developer traffic filter is Active.
- [../assets/example-acme-config.json](../assets/example-acme-config.json): the config built from that stack file. It points at [../assets/example-acme-ads-actions.json](../assets/example-acme-ads-actions.json), the Google Ads conversion actions saved unchanged from a read-only search.
- [../assets/example-acme-workspace-after.json](../assets/example-acme-workspace-after.json): the workspace export after CR-1 to CR-3, used for the diff and re-audit loop.
- [../assets/example-acme-exceptions.json](../assets/example-acme-exceptions.json) and [../assets/example-acme-evidence.json](../assets/example-acme-evidence.json): the accepted exception and the runtime evidence used below. Never copy them into a real audit; the templates start empty.

## Command

```bash
node scripts/audit-gtm-export.mjs assets/example-acme-export.json --config assets/example-acme-config.json
```

Exit code 1. The run ends with `27 FAIL, 36 WARN, 9 PASS, 3 INFO, 0 NOT CHECKED. Nothing was changed.`

## Expected output (excerpt, long lines shortened with ...)

```text
Status: RED (static). Score 37/100. Why: 11 P1 FAIL; 6 P2 FAIL on a biddable conversion; 16 P2 FAIL in total.
  Consent and privacy (weight 25): 25%  [R01 -102, R02 -60, R16 -40, R21 -20]
  Conversions and counting (weight 25): 18%  [R06 -72, R07 -48, R12 -48, R15 -44, R18 -40, R29 -40]
  Google tag and GA4 setup (weight 15): 29%  [R03 -48, R05 -10, R08 -11, R13 -48, R19 -40, R20 -60]
  Destinations and duplicates (weight 10): 42%  [R04 -44, R11 -64, R23 -40]
  Custom code and security (weight 10): 41%  [R09 -84, R22 -60]
  Triggers, variables and data layer (weight 10): 89%  [R10 -13, R30 -10]
  Versions, workspaces and naming (weight 5): 90%  [R14 -5, R31 -15]

FAIL P1 R20 google-tag-settings: tag "GA4 - Config (agency copy)" [2] sets debug_mode ("false"). ... The GA4 Developer traffic data filter is Active, so GA4 excludes that traffic for good. Remove the row, ... (R20:tag:2:debug-mode)
FAIL P1 R22 exposed-secrets: tag "HTML - purchase backup to GA4" [19] exposes what looks like a credential: "api_secret" in a URL XXXX... (22 characters). ... (R22:tag:19:secret)
FAIL P1 R09 custom-html: tag "HTML - legacy polyfills" [20] loads code from polyfill.io, a host that changed owner in February 2024 and was found serving malicious redirects in June 2024. ... (R09:tag:20:compromised-host)
FAIL P2 R16 exception-reach: exception "PV - internal traffic" on tag "LinkedIn - Purchase" [18] (probable ad-platform conversion) fires on a different event from every firing trigger ("CE - checkout events"), so the traffic it should exclude still converts. ... (R16:tag:18:exclusion-never-applies-21)
FAIL P2 R18 event-pattern-allowlists: trigger "CE - checkout events" matches {{_event}} matchregex "purchase|add_payment_info" without anchors, so it also matches purchase_failed, which is not in its list. ... (R18:trigger:20:unanchored-near-miss)
FAIL P2 R19 ga4-naming-and-limits: key event "generate_lead" is never sent exactly; "GA4 - lead" sends "Generate_Lead". ... (R19:tag:21:key-event-variant-generatelead)
FAIL P2 R23 duplicate-tags-and-pixels: GA4 purchase to G-XXXXXXXXXX is sent by 3 active tags ("GA4 - purchase", "GA4 - forward all events", "HTML - purchase backup to GA4"), and at least two can fire on the same event ... (R23:tag:4:conversion-senders-ga4-g-xxxxxxxxxx-purchase)
FAIL P2 R29 value-and-id-variables: variable "DLV - ecommerce.transaction_id" feeds orderId in tag "Ads - Conversion - Purchase" [6], and its default value is "none". ... (R29:variable:3:constant-order-id)
FAIL P2 R13 server-transport: tag "Meta Pixel - Purchase" [10] sends Meta Purchase from the browser with no event ID, while the configuration says the server container also sends Meta. ... (R13:tag:10:no-event-id-meta)
WARN P3 R11 destination-ids: Google Ads conversion action "Lead" (123456789/LeAdLaBeLxYz12) is enabled as a webpage action but no active tag in this container sends to it. ... (R11:ads-action:1002:ads-action-no-tag)
```

## What the agent does with it

The defects, in the order the change list treats them.

- Permission and secrets first. Six non-Google tags have no consent gate (R01 P1): both Meta pixel tags, the Meta Lead gallery template, the chat widget, the Measurement Protocol backup and the polyfill loader. decisions.md says non-Google advertising tags require ad_storage, ad_user_data and ad_personalization, so each gets the consent setting, not a trigger condition.
- The Measurement Protocol backup: R22 masks the value and names only the key and length. The agent does not test the secret. The GA4 property owner rotates it first, then the tag is removed (CR-4), which also clears one of the three purchase senders R23 lists.
- polyfill.io: removed outright (CR-5). If the site still needs polyfills, the developer self-hosts a vetted copy; the container is not the place for it.
- R02: the default is Custom HTML on All Pages. It sets all four signals to denied with no region list, which matches the EEA, UK and Switzerland decision but not the undecided rest of the world. The agent proposes the CMP's gallery template on Consent Initialization and puts the other regions under "Needs a decision" for the privacy owner. When the template arrives, its update must set all four signals (R02 checks the update too).
- R06 P1 and R13, "Meta Pixel - Purchase": it fires on the bare `cookie_consent_update`, so every banner interaction is a purchase, and it has no eventID while the server sends Meta Purchase too. One request (CR-1) because the test is one test order.
- `debug_mode` "false" in "GA4 - Config (agency copy)": the stack records an Active Developer traffic filter, so the config sets `ga4DeveloperFilter` to active and the script raises R20 to P1. Removing the row (CR-3) is a one-line change; its test checks the setting in Preview and the debug flag only on production requests sent without Tag Assistant, because Preview always adds the flag for the tester.
- Missing event IDs: R13 fails "Meta Pixel - Purchase" and "Meta - Lead (gallery template)" because the config says `meta:Purchase|Lead`. The base page view is not listed, so it is not checked.
- R07 FAIL plus R12: "GA4 - purchase" fires only on shop.example.com while the stack says quick-buy purchases complete on www.example.com, and its ecommerce setting is stored as text with no data source. CR-2 moves it to "CE - purchase" and restores the setting in the UI. It depends on CR-4, otherwise the Measurement Protocol backup still double-sends shop purchases.
- "LinkedIn - Purchase": the trigger `purchase|add_payment_info` is unanchored, so it also matches `purchase_failed` (R18), and its internal-traffic exception is a Page View trigger that can never block a custom event (R16). The script suggests anchoring the pattern; the agent goes further, because a purchase conversion should not fire on add_payment_info at all, and points the tag at "CE - purchase" (CR-11). The exception becomes a Custom Event `.*` trigger with the same cookie condition (CR-12).
- Order IDs: "DLV - ecommerce.transaction_id" defaults to "none", so every order that reaches Google Ads without an ID shares one and the later ones are dropped as duplicates (R29). Removing the default makes a missing ID visible (CR-10, together with moving "DLV - ecommerce.value" to Data Layer Version 2, R12).
- Key event case: "GA4 - lead" sends `Generate_Lead`; the key event is `generate_lead`, so the key event and any Ads import of it stay at zero (R19, CR-13).
- Google Ads leads: "Ads - Conversion - Lead (old account)" sends to retired 987654321 from a thank-you page view (R11 FAIL, R06 WARN), while the current account's primary Lead action has no sender at all (R11 WARN from the Ads export). Bidding on that account optimises toward zero leads. CR-14 replaces the tag with one for AW-123456789 and label LeAdLaBeLxYz12 on "CE - generate_lead". The export's "Calls from ads" action (category PHONE_CALL_LEAD, type AD_CALL) has no web tag by design and raises nothing.
- R15 and R08: "GA4 - forward all events" forwards `{{Event}}` on a `.*` trigger, which catches `gtag.config` and fires before the Google tag. CR-15 removes it; the events it carried that have no dedicated tag get one.
- R03 and R13 WARN: two Google tags load G-XXXXXXXXXX on every page, one routed to `https://sgtm.example.com`, one direct. CR-17 keeps the server-routed tag and moves it to Initialization - All Pages, the timing R08 needs.
- R03 page views: the stack says enhanced measurement counts browser-history page changes, and "GA4 - page_view (SPA)" also sends page_view on history changes while the Google tags keep the automatic page view. That is a real duplicate, not a maybe; CR-18 removes the manual tag.
- R05 WARN, linker not on every page: the runtime test showed the Google tag on every page stores `_gcl_aw` on landing, so the finding is refuted in the evidence file and leaves the score.
- Hygiene: "Copy of GA4 - purchase" (paused, default name), the paused Signup tag whose action is REMOVED in Google Ads, the never-firing Hotjar tag with a retired site ID, an unused trigger and variable, and naming drift go to batch 4 as their own release. The tag renames are excepted until 2027-03-31 by a decision (see below).
- Outside the file: the stack says gtm.js loads the container, so non-Google tags do run. The Settings tab, page senders, the data layer listener, GA4 data redaction, workspaces, permission levels and the Size indicator still need checking; they go in the report's "Checked outside the container" section as done or not checked, and [../assets/evidence-request.md](../assets/evidence-request.md) goes to the container owner.

## The change list (summary)

CR-1 to CR-3 are written out in full in [change-list.md](change-list.md). CR numbers are identifiers; the batches set the release order.

- Batch 1, permission and secrets (first release):
  - CR-1 "Meta Pixel - Purchase" [10]: drop the consent event trigger, require ad_storage, ad_user_data and ad_personalization, pass the data layer event_id. Closes R06:tag:10:consent-event-15, R01:tag:10:no-gate, R13:tag:10:no-event-id-meta.
  - CR-4 The GA4 property owner rotates the Measurement Protocol secret; then remove "HTML - purchase backup to GA4" [19]. Closes R22:tag:19:secret, R01:tag:19:no-gate and one sender in R23. The workspace diff shows the removal; it never prints the old or new secret.
  - CR-5 Remove "HTML - legacy polyfills" [20]. Closes R09:tag:20:compromised-host, R01:tag:20:no-gate.
  - CR-6 Replace "CMP - consent default" [11] with the CMP's gallery template on Consent Initialization - All Pages, with an update that sets all four signals. Closes R02:tag:11:not-consent-init. The rest-of-world default waits for the privacy owner.
  - CR-7 Require the three advertising consent types on "Meta Pixel - base" [9] and "Meta - Lead (gallery template)" [17]. Closes R01:tag:9:no-gate, R01:tag:17:no-gate.
  - CR-8 "HTML - chat widget" [14]: load over HTTPS and gate it under the category decisions.md names for support tools. Closes R01:tag:14:no-gate, R09:tag:14:http.
- Batch 2, counting and values:
  - CR-2 "GA4 - purchase" [4] on "CE - purchase" with its ecommerce source restored. Depends on CR-4.
  - CR-3 Remove `debug_mode` from "GA4 - Config (agency copy)" [2].
  - CR-9 "Meta - Lead (gallery template)" [17] on the accepted-lead data layer event with the event_id, instead of "Form - contact". Closes R06:tag:17:intent-19, R13:tag:17:no-event-id-meta.
  - CR-10 Remove the "none" default from "DLV - ecommerce.transaction_id" [3]; set "DLV - ecommerce.value" [4] to version 2. Closes R29:variable:3:constant-order-id, R12:variable:4:dlv-version-1.
  - CR-11 "LinkedIn - Purchase" [18] on "CE - purchase". Closes R18:trigger:20:unanchored-near-miss.
  - CR-12 An internal-traffic exception that works on custom events (Custom Event `.*`, "Cookie - internal" equals true) for every conversion that should exclude internal traffic. Closes R16:tag:18:exclusion-never-applies-21.
  - CR-13 "GA4 - lead" [21] sends `generate_lead`. Closes R19:tag:21:key-event-variant-generatelead.
  - CR-14 Replace "Ads - Conversion - Lead (old account)" [7] with a Lead tag for AW-123456789 on "CE - generate_lead". Closes the R11 retired and enabled-action findings and R06:tag:7:page-based-14.
  - CR-15 Remove "GA4 - forward all events" [5]. Closes R15:trigger:12:gtag-config, R15:tag:5:forwarder and the R08 early-event WARN.
  - CR-16 Remove "UA - Pageview" [12] and "GA Settings - legacy". Closes R04:tag:12:ua-tag, R04:variable:5:gas and the retired UA ID.
- Batch 3, attribution and session:
  - CR-17 Remove "GA4 - Config (agency copy)" [2]; move "Google tag - GA4" [1] to Initialization - All Pages. Closes R03:id:g-xxxxxxxxxx:duplicate-google-tags, R13:id:g-xxxxxxxxxx:mixed-routes.
  - CR-18 Remove "GA4 - page_view (SPA)" [3]; enhanced measurement owns route changes. Closes both R03 page view WARNs.
  - CR-19 "HTML - set checkout data" [15] uses `google_tag_manager[{{Container ID}}].dataLayer.set()` instead of a push. Closes R08:tag:15:setup-push.
- Batch 4, hygiene (its own release):
  - CR-20 Delete the paused, never-firing and unused items, add notes to conversion tags, rename the triggers and variables; tag renames follow the clean-up release.
- Needs a decision:
  - "Ads - Conversion - Purchase" [6] is held back only by "Exception - marketing denied", a deny-list that fails open and contradicts advanced mode (R01 WARN, R07 mixed exceptions). Owner: privacy owner. Default if no answer by the release date: leave it, since the tag already follows its built-in consent checks.
  - "Meta Pixel - Purchase" reads {{DLV - user email}} (R21 WARN). Owner: privacy owner with the paid social owner. Default: remove it from the browser tag and leave matching to the server.
  - begin_checkout has no trigger (R30 WARN). Owner: analytics lead. Default: no change.
- Expected metric movement, told to each owner before the release: Meta Purchase falls (no more consent-click purchases, and browser and server copies deduplicate); GA4 purchases per order move to one (www purchases appear, backup and forwarder duplicates disappear); GA4 users and sessions rise from the CR-3 date (debug traffic no longer filtered); the current Google Ads Lead action starts receiving conversions after CR-14; GA4 page views fall after CR-18.

## Runtime evidence and exceptions

```bash
node scripts/audit-gtm-export.mjs assets/example-acme-export.json --config assets/example-acme-config.json \
  --exceptions assets/example-acme-exceptions.json --evidence assets/example-acme-evidence.json
```

- R06:tag:10:consent-event-15 is confirmed: on staging, two banner interactions sent two Meta Purchase requests with no order.
- R05:tag:13:linker-not-every-page is refuted and leaves the score.
- R31:container:naming-tags is accepted until 2027-03-31 with its decision reference and approver. It stays a WARN marked accepted, and the governance area moves from 90% to 91%.
- The score stays 37 and the status stays RED with a static label: ten other P1 FAILs and sixteen P2 FAILs have no evidence entry yet. The label reads confirmed only when every P1 and P2 FAIL has one.

## Re-audit loop after CR-1 to CR-3

```bash
node scripts/diff-gtm-exports.mjs assets/example-acme-export.json assets/example-acme-workspace-after.json
node scripts/audit-gtm-export.mjs assets/example-acme-workspace-after.json --config assets/example-acme-config.json
```

The diff, shortened:

```text
Risky changes (2):
  tag "GA4 - purchase" [4]: trigger added to a conversion tag (GA4 purchase)
  tag "Meta Pixel - Purchase" [10]: Custom HTML code changed
All changed settings (8):
  tag "GA4 - Config (agency copy)" [2] parameter.configSettingsTable[debug_mode].parameterValue: false -> (none)
  tag "GA4 - purchase" [4] firingTriggerId: 11 -> 10
  ...
  tag "Meta Pixel - Purchase" [10] consentSettings.consentStatus: notneeded -> needed
  tag "Meta Pixel - Purchase" [10] firingTriggerId: 10, 15 -> 10
Added (1):
  variable "DLV - event_id" [10]
```

- Both risky lines are named in CR-1 and CR-2, and nothing else changed, so the configuration check passes.
- The re-run is headed "Workspace export, pending change" and ends `21 FAIL, 33 WARN, 11 PASS, 4 INFO`, RED (static), 43/100: 8 P1 FAILs (from 11), 13 P2 FAILs (from 16).
- Cleared: R01:tag:10:no-gate, R06:tag:10:consent-event-15, R07:tag:4:host-scope-11, R07:tag:4:scoped-11, R12:tag:4:ecommerce-type, R12:tag:4:ecommerce-source, R13:tag:10:no-event-id-meta, R20:tag:2:debug-mode.
- New: only R14:container:not-published, an INFO line that every workspace export raises and that is never scored. No new P1 or P2 FAIL.
- R14:container:unnamed-version also drops out, but only because a workspace export has no published version to name. It is not fixed: give the new version a name and description when it is published.
- The score rises from 37 to 43 because every cleared finding raises its area (conversions from 18% to 32%, Google tag from 29% to 43%). Track the P1 and P2 counts and the cleared finding IDs next to it while batches 1 and 2 are in flight.
- Still open in the re-run, as expected: R23 on "GA4 - purchase" (three senders until CR-4 and CR-15 ship) and R13 on "Meta - Lead (gallery template)" (CR-9).
- After the owner publishes, the live version is exported again and audited with the same config; each request closes with the diff, the re-run, the runtime record and the destination check.

## Regression fixture

[../assets/regression-fixture.json](../assets/regression-fixture.json) holds one tag, trigger or variable per rule case, with a negative case for most rules. One command checks the fixture, the Acme runs above, the diff, its masking of credential-like values and its risky reasons, the export versus API spelling, an assembler round trip, a server container smoke test, the input check, rule paths that need extra options and the page inventory snippet in a sandbox:

```bash
node scripts/check-regression.mjs
```

Expected: fourteen `ok` lines and `All regression checks passed.` The fixture run itself ends `47 FAIL, 69 WARN, 7 PASS, 3 INFO`, RED (static), 28/100. Cases include, among others:

- "CMP update on choice event": R02 WARN P3 for Custom HTML timing, never FAIL, and no R01 finding; its update sets all four signals.
- "HTML CMP v2 default with v1 update": R02 FAIL P2, the update leaves ad_user_data and ad_personalization at their denied default.
- "Meta Purchase on consent event scoped to thank-you" (requires ad_storage): R06 WARN P2 as page-based, not FAIL.
- "Meta base on bare consent event": R01 FAIL; the consent event is not a gate.
- "Reddit with deny-list exception": R01 FAIL with the fails-open note.
- "TikTok wrapped in OneTrust check": R01 WARN for a code gate, and no R02 FAIL.
- "Consent default with two signals granted": R02 FAIL for the missing ad_user_data and ad_personalization, WARN for granted with no region.
- "Ads call on tel: link": R06 WARN P2, a click-based action, not FAIL; "Floodlight site-visit counter" on All Pages: R06 WARN P3.
- "GA4 event with debug_mode from a lookup": R20 WARN, while the literal "false" on "Google tag G2 with risky settings" stays FAIL.
- "Ads website call conversion on all pages" (`awcc`): no R06 finding and no unclassified WARN, but R01 WARN P2, because Google says support for Phone Call Conversions is pending. "Ads user-provided data event" (`awud`): no R01 or R06 finding.
- "HTML resets the data layer" and "JS - resets dataLayer": R09 and R27 FAIL P2; "HTML initialises the data layer safely": no finding.
- A Page View exception on a custom event tag (R16 FAIL) next to a `.*` exception that passes; Unlimited with two purchase triggers (R17 WARN P2: count the requests in Preview) next to an Unlimited conversion that is also a cleanup tag on the same event (R17 FAIL P2); `purchase|add_to_cart` near `purchase_failed` (R18 FAIL) next to an anchored list that passes; `ga_note`, 26 parameters and `Sign_Up` against key event `sign_up` (R19 FAIL); `user_id` from an email variable (P1) and a literal `campaign_source` (R20); a GA4 email parameter (R21 P1); an `api_secret` of X characters, an X-only Slack webhook path and a Constant named "Const - client secret" (R22 P1, masked); twin Meta base tags (R23); a self-load and an unknown second container (R24); a gallery template edited locally (R25); a 10.5 KB Custom HTML tag (R26); a Custom JavaScript variable with no return (R27); an unbounded timer (R28); an order ID variable with a default (R29); a trigger on `Purchase` against plan event `purchase` (R30); "Untitled Tag" (R31).

When a rule changes on purpose, update [../assets/regression-expected.json](../assets/regression-expected.json) in the same change and say why in its `_readme`.
