How to test analytics events and the tracking plan
Analytics events are tested against a tracking plan: a document describing each event, when it fires, and its properties and types. The plan is compared with reality in the Network tab or a debug mode, checking the name, types, duplicates (reload, retry), tracking consent and consistency across platforms. A broken event does not fail a test but spoils decisions, so it is a defect.
Product Engineering · Metrics and analytics
The payment event fires twice after a reload. The dashboard is happy while revenue does not grow.
The team celebrates: payment conversion is up 12%. A day later an analyst notices that revenue in the accounting system has not changed. It turns out the payment success page sends the checkout_completed event on every load, so users who refreshed the page are counted twice. A broken event raises no errors and fails no test, but it poisons decisions: what to develop, what to switch off, whether an A/B test won. So it is a real bug and is checked as seriously as functionality.
How it works and why. An event passes through a chain, and a defect can sit on every link. The user performs an action, the app code calls the SDK, the SDK sends a request to the analytics service, which processes the data and shows it in a report. The user and the report see only the start and the end, and what lies between is measurable only if you look at intermediate points. For QA the link "request to the service" is convenient: the exact name, properties and number of events are visible there, and report processing does not distort them.
The path of an event to the report
A tracking plan is a document (a table, a schema) that describes every event: the name, when it fires, required and optional properties with types, platforms. It is the "specification" for testing analytics: without it you cannot say whether an event is sent correctly. A fragment of a plan:
{
"event": "checkout_completed",
"fires": "after the server confirms payment, once per order",
"properties": {
"order_id": "string, required",
"amount": "number, required, in the order currency",
"currency": "string, ISO 4217 code in upper case",
"platform": "web | ios | android"
}
}
Example: comparing the plan and the fact. In the Network tab after a successful payment this request was found:
{
"event": "CheckoutDone",
"amount": "49.90",
"currency": "uah"
}
// shortened: the same event was registered once more
Comparing it with the plan gives a whole list of defects, and each has a consequence:
- the name
CheckoutDoneinstead ofcheckout_completed: the event will not reach a funnel that looks for the name from the plan; amountas the string"49.90"instead of a number: the amount cannot be summed, the report shows zero or an error;currencyin lower case: a mismatch with the value dictionary, grouping splits into "UAH" and "uah";order_idandplatformare missing: the event cannot be linked to an order or broken down by platform;- the event is sent twice: revenue is doubled for those who refreshed the page.
A duplicate is caught by an automated test: intercept requests to the service, open the success page, reload it and count the events:
const events: { event: string; amount?: unknown }[] = [];
// the URL depends on the analytics tool
await page.route('**/collect', async (route) => {
events.push(JSON.parse(route.request().postData() ?? '{}'));
await route.continue();
});
await page.goto('/checkout/success?order=1001');
await page.reload();
const done = events.filter((e) => e.event === 'checkout_completed');
expect(done).toHaveLength(1); // no duplicate after reload
expect(typeof done[0]?.amount).toBe('number');
What else is checked.
- Firing: the event is sent exactly when needed (clicking "Pay" is not a successful payment) and not sent when it should not be. It is better to write when in the plan, as in the example: "after the server confirms";
- Duplicates: reloading the success page, a double click, a request retry, going "back";
- Identification: after sign-in events are tied to the user, and the anonymous session is correctly linked to the account;
- Consent: if the user declined tracking, events that need consent are not sent (before and after the refusal), and when the decision changes the behaviour updates. This is not only data quality but also a legal requirement;
- Platforms: web, iOS and Android send the same names and properties.
Where to look: the Network tab in DevTools, the tool's own debug mode (GA4 DebugView, Mixpanel Events, formerly Live View, Amplitude Event Explorer), a proxy such as Charles for mobile apps. Names of these views change, so check your tool's documentation before you work.
Limits and alternatives. A check in DevTools shows what was sent from the client, not what reached the report: the service may reject an event by schema, filter bot traffic or deduplicate. So it is important to also compare the final number in the report on a sample. Automated tests with interception depend on the request format of the service and break when the SDK changes: keep checks at the level of "name + key properties", not the full payload. Some events are sent by the server and are not visible in the browser: look in server logs or the queue. For some events, such as showing a banner, there is no deterministic scenario, and they have to be checked on a sample.
Common mistakes.
- Considering an event correct because it is in the report: the name, the type of the amount and duplicates remain unchecked.
- Checking only the success path: reload, retry and "back" duplicate events.
- Having no tracking plan or not updating it: there is no reference to compare with.
- Not testing the refusal of consent: it is a legal risk, not only data quality.
- Checking only web: names or properties diverge on iOS and Android.
Check yourself
The event is sent on a click of "Pay", while the plan says "after a successful payment". Why is that a defect and what will it spoil?
Answer
A click does not guarantee success: the payment may be declined and the event is already gone. Conversion and revenue will be overstated, and an A/B test will compare the wrong people. The event is tied to server confirmation, and QA checks it on a successful, a declined and a cancelled payment.
A user declined analytics cookies, yet requests to the analytics service are still visible in Network. What is it and why does it matter?
Answer
It is a consent violation: events that need consent must not be sent until the user allows it. Besides data quality it is a legal risk (personal data rules). Check the state before the decision, after the refusal and the update after the decision changes.