# Code, security and destination rules: R04, R09, R11, R22, R23, R24, R25, R26, R27

Checked on 2026-11-01 against Google's allowlist and blocklist page, container size help, Custom JavaScript variable help, template permission format, the Measurement Protocol sending page and Cloudflare's polyfill.io notice; the data layer guide and the Google Ads MCP server's search tool re-checked on 2026-11-02, and Cloudflare's notice on 2026-11-06.

## R04 retired-tag-types

- FAIL P2 (WARN P3 when paused): Universal Analytics tags (`ua`, `ga`), Custom HTML loading analytics.js or a UA gtag ID, Google Optimize tags or code. Standard UA properties stopped processing on 1 July 2023 and Optimize on 30 September 2023; the code still runs and sends nothing usable.
- WARN P3: the legacy GA4 Configuration type (`gaawc`, converted to Google tags in September 2023: re-export and check); legacy GA Settings variables (`gas`); templates Google lists as obsolete (`cts`); the Optimize anti-flicker snippet (`async-hide`) in Custom HTML, which only hides the page until its timeout; a Google Ads remarketing tag on every page for an AW- ID that a Google tag for the same ID also loads on every page (check in Network whether remarketing hits double).
- Agent adds: before removing anything, check whether another tag reads a variable or cookie the old tag sets.

## R09 custom-html

- FAIL P1: Custom HTML loads code from a host with a public compromise record. The seed list holds polyfill.io and its subdomains: the domain changed owner in February 2024 and was found serving malicious redirects in June 2024 (Cloudflare, 26 June 2024). The list is small on purpose; add hosts from your security team's feed in the script's COMPROMISED list.
- FAIL P2: code loaded over plain HTTP.
- FAIL P2 (key datalayer-reassigned): code that assigns a new array to the data layer (`dataLayer = [...]`, `window.dataLayer = []`, `new Array`), anything but the `window.dataLayer = window.dataLayer || []` form. Google's data layer guide says never to overwrite or re-assign window.dataLayer: the container keeps listening to the old array, so every later push (purchases, leads) is lost without an error. Page code can do the same; the page inventory's "GTM listening to" line catches it at runtime.
- WARN P3: third-party script hosts; "Support document.write" on; eval or new Function; quoted references to non-string variables (they arrive as text); in-house templates with no gallery reference; writes to cookies or browser storage, which need the same consent as sending.
- WARN P4: a polling timer (setInterval) in a tag that fires on every page.
- Why: Custom HTML runs with full page access, and Google's help names built-in templates as the way to avoid performance and malware issues.
- Agent adds: for each vendor snippet, propose the vendor's gallery template with declared permissions. If the container loads with a G- or AW- ID, Custom HTML and community template tags do not run at all since 9 July 2026.
- Confirm after removal: no request to the flagged host on any page type.

## R11 destination-ids

- FAIL P2: with `--expect-ids`, an ID the script reads that is not listed, used by an active tag that can fire; with `--retired-ids`, a retired ID in such a tag.
- FAIL P2, with `--ads-actions`: a Google Ads conversion tag whose ID and label match no conversion action in the export, or match a REMOVED or HIDDEN action.
- WARN P3: unexpected or retired IDs only in paused, never-firing or variable-only use; the same ID typed into two or more tags (put it in one Constant); unclassified tag types while ID lists were given; an ENABLED webpage conversion action with no tag in the container (fine if imported or sent server-side; if it is primary, bidding optimises toward zero); a Google Ads tag for an account the export does not cover.
- PASS: an inventory of every ID with its tags and variables and a status (expected, retired, not on the list). Google Ads tags matched to an action with primary_for_goal true are marked biddable, which feeds the status rule.
- NOT CHECKED note: with no `--expect-ids` and no `--retired-ids`, unexpected and retired IDs are not compared; the PASS line says so, the note appears under Not checked, and every ID is listed as "no expected list given". A PASS without lists never means "no unexpected IDs".
- Where IDs are read: G-, AW-, DC- and UA- patterns in tag parameters and every variable a tag reaches (Constants, Lookup and RegEx Tables, GA Settings); Google Ads conversionId (conversion, remarketing, website call and user-provided data tags) and Floodlight advertiserId digits, with an optional AW- or DC- prefix ignored when comparing; Meta, TikTok, LinkedIn and UET IDs in Custom HTML; pixel, partner, tag and site ID parameters in vendor templates; variables no tag reaches. Not read: IDs inside destination tags, Custom JavaScript variables, scripts loaded from other hosts.
- Google Ads cross-check: call the search tool of Google's Google Ads MCP server with customer_id (digits, no dashes), resource `conversion_action` and fields conversion_action.id, conversion_action.name, conversion_action.status, conversion_action.type, conversion_action.category, conversion_action.primary_for_goal, conversion_action.counting_type and conversion_action.tag_snippets. The tool builds the GAQL itself and returns rows keyed by field path (for example "conversion_action.status"). Save the returned list to JSON unchanged and pass it with `--ads-actions` (the access set-up, with the server's mutate tools off, is in [outside-the-file.md](outside-the-file.md) check 8); for tools that take GAQL, the equivalent is `SELECT ... FROM conversion_action`. The script reads the AW-ID/label pairs inside the tag snippets whatever the row shape, and R06 reads the category. Field names checked against the API v26 field reference and the server's search tool code on 2026-11-02.
- Agent adds: build the expected list from stack.md, never from the container. Ask about every ID the stack does not explain. Purchases normally count every conversion and leads one per click; check the counting type against the tracking plan.

## R22 exposed-secrets

- FAIL P1, web containers: a credential-like key (api_secret, client_secret, access_token, refresh_token, private_key, auth_token, password) with a quoted literal or URL value of 8 characters or more, or one resolved from a Constant; a credential-named parameter or Constant with such a value; or a known secret format (Stripe live secret keys, AWS access keys, Slack tokens and webhook paths, GitHub tokens, private key blocks, Bearer tokens) anywhere in tags, variables or templates. Google says the Measurement Protocol api_secret is private and must not be in client-side code; a web container is delivered to every visitor.
- WARN P2: Google API keys (often public by design for Maps; confirm the key is restricted), JWT-like strings, Stripe test keys.
- WARN P3, server containers: secrets in server tags are not sent to browsers but are visible to everyone with container Read access.
- Masking: every format prints the key name, the entity, the first four characters and the length, never the value. The diff script masks with the same detectors, so a rotated or newly added secret shows as a masked, risky change and never prints in full. The regression check fails if an unmasked fixture value appears in a finding or in diff output.
- Remediation is the owner's: rotate the secret at its source and move the call server-side. The audit never copies, tests or rotates a secret.
- Confirm: after rotation, the owner confirms the old secret is deleted at its source and a re-run shows R22 PASS.

## R23 duplicate-tags-and-pixels

- FAIL P2: two active tags with identical type and settings that send data and can fire on the same event.
- FAIL P2: the same vendor base initialised by two or more active tags that fire on every page: Meta `fbq('init')` or the Meta template, TikTok `ttq.load`, LinkedIn partner ID, Microsoft UET `ti`, Hotjar site, Pinterest load, Microsoft Clarity project. Clones already reported are not reported again here.
- FAIL P2: one conversion reaches one destination from two or more active tags that can fire on the same event: the same GA4 conversion event to one measurement ID (dedicated tags, Measurement Protocol purchases, wildcard forwarders), the same Google Ads ID and label, or the same ad platform standard event. Allowlist forwarders are R15's job.
- WARN P2: the same conversion and destination from tags on triggers that never fire on one event. A page-based and an event-based sender both fire for one order, so confirm in Preview that one order produces one request.
- WARN P3: identical configuration on different triggers (merge and check the triggers never overlap). WARN P4: identical helper tags.
- Confirm: one page load and one test order. Pass: one base request per pixel ID and one conversion request per order per destination.

## R24 nested-containers-and-zones

- FAIL P2: Custom HTML loads this same container (every tag can run twice) or a GTM container not on the expected list; a zone child container not on the expected list. Whoever controls that container can change what runs on the site.
- WARN P3: an expected second container (record its owner and which events each container owns); a container with no expected list given; a zone with type restrictions off (its child can run Custom HTML); a zone with no boundary conditions.
- Confirm: `scripts/page-inventory.js` lists every loaded container ID; open each in Preview.

## R25 template-permissions

- WARN P3: a gallery template edited locally (`galleryReference.isModified`), so it no longer receives gallery updates; network permissions (inject_script, send_pixel, inject_hidden_iframe) allowing any host or a wildcard host.
- WARN P4: read permissions set to any (read_data_layer allowedKeys, get_url urlParts or queriesAllowed, cookie access); inject_script from public package CDNs (cdn.jsdelivr.net, unpkg.com) without a pinned version, so a new package release runs on the site immediately.
- PASS: unmodified gallery templates with declared hosts.
- Why: a template is sandboxed only as far as its permissions; broad permissions plus local edits make it Custom HTML with extra steps.

## R26 code-weight

- WARN P4: a Custom HTML tag over 10 KB of code (set with `--code-weight-kb`), likely a pasted library. Google advises serving static JavaScript from the site instead of the container.
- INFO: export size, custom code share and the ten largest code items. Google publishes no numeric container size limit; the Versions page Size indicator is the official measure (optimise above 70%), so start from this list when it is high.

## R27 custom-javascript-variables

- FAIL P2: a Custom JavaScript variable with no return statement. Google's help says it must be an anonymous function that returns a value; otherwise every tag and trigger reading it gets undefined.
- FAIL P2 (key datalayer-reassigned): a Custom JavaScript variable that assigns a new array to the data layer, as in R09. It runs every time a tag or trigger reads it, so the container loses its data layer on the first read.
- WARN P3: side effects (dataLayer.push, cookie or storage writes, network calls, DOM writes). Variables run whenever a tag or trigger reads them, often several times per event, so the effect repeats.
- WARN P3: parsing the _ga cookie. Use the built-in Client ID and Session ID variables (added 11 December 2025) or the Analytics Storage variable.
- Confirm: Preview's Variables tab on two events shows a defined value and no extra data layer events or requests.
