Why generated tracking code needs proof
Tracking code is a contract between three things: the tracking plan, which says
what each event is called, what parameters it carries, where it fires and which consent category it depends on; the
site, which pushes messages into the Data LayerA structured object on a web page that passes values to a tag manager for tags to use.; and the Tag ManagerTag management system. container,
which reads those messages and decides what to send. Code that breaks the contract usually still runs. The container
does not know that booking_confirmed should have been book_appointment, that a parameter called customer_email
should not exist, or that a page path pattern also matches the staff area.
A model writing that code fills every gap with the most plausible continuation, as the guide to how language models generate text explains. Where the plan's names are not in front of it, it invents names that look like the conventions it has seen. Where the markup is not in front of it, it guesses at selectors and URLs. Where its training text was older than the current documentation, it reproduces older patterns. The output is a draft to be proved, not a setup to be pasted. The academy exercise on proving a sewing machine retailer's generated revenue query and sample tag practises proving one such draft, a fabric sample request tag whose names, postcode parameter and loose page pattern all departed from its plan row, and previewing the rebuild with consent accepted and then refused.
The failures that matter are quiet, and the routine below is built to surface each one.
| Failure | What it looks like | Where the routine catches it |
|---|---|---|
| Invented names | An event or parameter the plan never defined, so reports split or stay empty | Checking every name against the plan before preview |
| Personal data in values | An email address, name or phone number copied into a parameter or a page path | Reading every value's source and testing with invented details |
| Over-matching pattern | A trigger or regular expression that also fires on test, staff or unrelated pages | Testing the pattern against pages that should not match |
| Under-matching pattern | A trigger that misses a template, a language version or a query string | Testing against every page the plan's location column names |
| Consent ignored | A tag that sends data when the visitor refused, or a custom script that sets its own storage | Running preview with consent granted and refused |
| Wrong timing | A push before the values exist, or a tag that reads a variable on the wrong event | Reading the data layer state on the firing event |
Before you start
- The tracking plan row for the event: its name, parameters with types, trigger condition, location, destinations and consent category. If no row exists, write it first, using the measurement plan for the business question the event answers.
- The data layer specification, if the site has one, as the data layer guide describes: what is pushed, when, with which keys and value types.
- The template markup of the pages involved, saved from the template or from a test page filled with invented values, plus a list of the site's URLs that the trigger should and should not match.
- An approved AI tool. One your organisation permits for this work. Follow the data minimisation tutorial for what may go into it.
- Edit access to a workspace in the container and a role in the GA4 property that can open DebugView.
- The container's change rules, as set out in the container governance guide, and the team's container publish checklist.
The steps
Write the request from the tracking plan row
Start from the plan, not from a description in your head. Copy the row into the request: the event name exactly as written, each parameter with its type and where its value comes from, the condition that should fire it and the conditions that must not, the pages it applies to and the consent category. Say what you want back: a data layer push for the developer, the variables and trigger for the container, and the tag, using a built-in template where one exists rather than custom HTML, as the tags, triggers and variables guide advises. Ask the model to list every assumption it had to make and every name it used that was not in the request.
Give the model the plan's names and the page's real markup, never customer data
Paste the template's markup or the relevant fragment, the site's existing data layer conventions and the GA4 event and parameter names the plan uses. Without real markup the model guesses at element identifiers and page paths; without the plan's names it invents its own. Leave out anything a customer produced: no real confirmation pages, no form submissions, no exported events. Replace real values with invented ones of the same shape. The model needs the structure to write the code; it does not need the data that will later flow through it.
Read the code line by line against the plan
Run nothing yet. Read the generated push, variables, trigger and tag one line at a time and mark each as matching the plan, differing from it or unclear. Check where each value comes from: a data layer key, a page element, the address bar, a cookie. Check that the push happens at the moment the plan describes, after the booking or order is confirmed rather than on the button click, which the data layer guide treats as part of the contract. Compare the model's explanation with what the code actually does; the explanation can describe the code the model meant to write. In any custom HTML or custom JavaScript, look for anything beyond the stated purpose: extra requests, storage, or a third-party script loaded from an address nobody recognises.
Check every event and parameter name against the plan
List every event name, parameter name and data layer key the code uses and set it beside the plan row. Each must match the plan exactly, including case and separators, because a variable that reads a key with a different spelling returns nothing and a tag that sends a new parameter name creates a new, empty column in reports. Where the plan follows GA4's documented names for an event, the code should too; the GA4 events and parameters guide explains how recommended and custom event parametersA named value sent with an analytics event that describes it, such as a page location, form name or item price. differ. Any name the model added that the plan does not hold is either removed or proposed as a change to the plan, never shipped by default.
Check what personal data the code could send
For every value the code sends, ask what it could contain on a real page. A parameter filled from a form field, the page title, the full address or a confirmation message can carry a name, an email address or a phone number. The data layer guide's rule is that personal dataAny information relating to an identified or identifiable living person, such as a name, email address, location data or an online identifier. does not belong in the data layer, and the guide to keeping personal data out of analytics lists the routes it takes, from query strings to page titles. Remove any value whose source can hold personal details, and where the plan needs an identifier, use the internal one the plan names. Then fill in the test form with obviously invented details so that, if anything leaks, the preview in a later step shows it.
Test the trigger and any regular expression against pages that should and should not match
Take the list of URLs gathered before you started and split it in two: pages where the tag must fire and pages where it must not, such as staff screens, test bookings, other templates and language versions. Check the trigger's conditions, and any regular expression in a trigger or a regex table, against every entry in both lists. A generated pattern is often written for the example in the prompt and is either too loose, matching the staff area that shares a path, or too tight, missing the query string a payment provider adds. Where a blocking rule already exists for internal traffic or a staging hostname, use it as an exception rather than writing a new one.
Run it in preview and DebugView with consent granted and refused
Load the workspace in preview and follow the debugging and preview tutorial: find the event in the timeline, confirm the tag fired on it and not on others, read the resolved values in the Tags and Variables tabs, and read the data layer state on the firing event. Then confirm arrival in DebugView and, in the browser's network panel, what actually left the page. Do it twice: once after accepting the consent banner and once after refusing it. The consent mode guide explains that Google's tags adjust to the consent state on their own, while other vendors' tags need consent settings in the container that hold them until the required types are granted; the preview panel shows when a consent requirement held a tag back. A tag that behaves the same under both choices needs a second look. If the tag does not fire, the tag not firing guide works through the causes.
Review, name and publish through the container's change rules
Generated code goes through the same door as any other change. Name the tag, trigger and variables to the container's conventions, write the workspace description, and hand it to whoever holds publish rights for review, as the container governance guide sets out. Say in the description that the code was drafted with an AI tool, so the reviewer reads custom script with that in mind. Work through the container publish checklist before the version goes live, and check the event on the live site afterwards, since production templates, banners and caching can differ from what preview saw.
Record the change and the prompt beside the tracking plan
Update the tracking plan row with the implementation status and the version that shipped it. Keep the request, the model's output, the changes made during review and the test results with the row or in the container's documentation. The saved request, with its corrections, is a better starting point for the next event than a fresh prompt. Where the team keeps an inventory of AI uses, add this one, so a later audit knows which tracking was drafted with a model.
Generated tracking code is one case of the wider rule in the AI for analysis and reporting guide: anything a model produces that feeds a number is checked before the number is used. The applications hub places this routine among the other AI tasks a marketing team runs. Before the generated push or tag ships, the AI-written code review checklist turns this routine and its companions into one tickable gate. The academy capstone on a year of AI in production for a children's shoe retailer practises writing that gate and applying it to a fitting guide tag that went live without a preview, inside a plan that also launches a chat assistant and tests three agency proposals for ad automation.
A cycle repair chain checks a generated booking event (illustrative)
Jurnavik Cycle Repairs checks a generated booking-confirmed push and trigger
Jurnavik Cycle Repairs, an invented chain of 7 bicycle workshops with online booking, asks an AI tool for a push and a
trigger for a confirmed service booking. The tracking plan row names the event service_booked with 4 parameters:
workshop_id, service_type, value and currency, consent category analytics.
The analyst pastes the plan row and the confirmation template with invented values. The model returns a push, a data layer variable for each key, a custom event trigger and a GA4 event tag. The line-by-line read and the checks find 3 problems:
| Finding | Where | Fix |
|---|---|---|
A fifth parameter, booking_ref_type, that the plan never defined | Push and tag | Removed; proposed to the plan owner, who declined it |
customer_email filled from the form's email field | Push | Removed; the plan's rule bans personal data in parameters |
| A page path pattern matching the confirmation page and 3 staff booking screens | Trigger | Replaced with the custom event trigger on the push alone, with the internal traffic exception |
Preview with consent granted shows the tag firing once on the confirmation with 4 parameters; with consent refused, the GA4 tag adjusts as documented and a third-party pixel the model added is held back by its consent setting. The team removes the pixel, which nobody had asked for. The publisher reviews the workspace against the checklist, and the plan row records the version, the prompt and the 3 fixes. A live check the next morning finds 12 bookings recorded, each carrying all 4 parameters and no email address.
Common mistakes
- Asking from memory instead of the plan. Without the plan's names in the request, the model supplies its own and the reports split.
- Pasting a real customer's page as context. The template with invented values gives the model everything it needs; customer details do not belong in a prompt.
- Treating "it fired" as "it is right". Firing proves a trigger matched once; names, values, patterns and consent are separate checks.
- Testing only the page that should match. Over-matching triggers are found by testing the pages that should stay quiet.
- Testing with consent granted only. The refused branch is where generated custom script most often misbehaves.
- Accepting custom HTML where a template exists. Ask for the template; review every line of any script that remains.
- Skipping the container's review because the code came quickly. Generated changes go through the same publish rules as any other.
- Not recording the prompt and the fixes. The next event starts from scratch and repeats the same mistakes.
