analytics-tracking-testing
Validate that analytics and marketing tracking fire CORRECTLY: GA4/GTM dataLayer events, Meta/TikTok/LinkedIn pixels, and ad-tech tags. Covers building a tracking plan as the contract, intercepting collect-endpoint beacons and dataLayer.push in Playwright, asserting event name + params + values + timing + de-duplication, Consent Mode v2 gating, CI regression gating, and news-media events (article-view, scroll-depth, paywall). Use when: "test analytics tracking," "GA4 event test," "verify the pixel fires," "dataLayer test," "tracking plan," "Meta Pixel dedup," "scroll-depth tracking test," "gate tracking in CI." Not for: whether tracking is ALLOWED to fire under consent law (GDPR/CMP) — that is compliance-testing; this skill checks the data is CORRECT. SEO meta tags / structured data — out of scope. Related: compliance-testing, playwright-automation, api-testing, qa-project-context.
kindlmann · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add petrkindlmann/qa-skills --skill analytics-tracking-testingAbout this skill
name: analytics-tracking-testing description: >- Validate that analytics and marketing tracking fire CORRECTLY: GA4/GTM dataLayer events, Meta/TikTok/LinkedIn pixels, and ad-tech tags. Covers building a tracking plan as the contract, intercepting collect-endpoint beacons and dataLayer.push in Playwright, asserting event name + params + values + timing + de-duplication, Consent Mode v2 gating, CI regression gating, and news-media events (article-view, scroll-depth, paywall). Use when: "test analytics tracking," "GA4 event test," "verify the pixel fires," "dataLayer test," "tracking plan," "Meta Pixel dedup," "scroll-depth tracking test," "gate tracking in CI." Not for: whether tracking is ALLOWED to fire under consent law (GDPR/CMP) — that is compliance-testing; this skill checks the data is CORRECT. SEO meta tags / structured data — out of scope. Related: compliance-testing, playwright-automation, api-testing, qa-project-context. license: MIT metadata: author: kindlmann version: "1.1" category: specialized
Quick Route
| Situation | Go to |
|---|---|
| Assert one GA4 event fired with correct params | Intercepting GA4 beacons |
| Treat the tracking plan as a validated contract | The Tracking Plan Is the Contract |
| Verify dataLayer.push shape (not the beacon) | Asserting dataLayer.push |
| Pixel + server CAPI deduplication (event_id) | Pixels and Server-Side Deduplication |
| Events must/mustn't fire by consent state | Consent Mode v2 Gating |
| Capture every pixel in one reusable fixture | references/capture-fixture.md |
| News-media: article-view, scroll-depth, paywall | News-Media Events |
| Fail the build on a tracking regression | Regression-Gating in CI |
| Hundreds of events, many domains, small team | Buy vs Build |
Discovery Questions
First: check .agents/qa-project-context.md in the project root and skip anything it already answers (stack, tag manager, consent platform, target environments). An unfilled template answers nothing; treat it as absent and take the answers from the application's contract or configuration.
- Which tracking destinations are live? GA4 (
/g/collect), Meta Pixel (facebook.com/tr), TikTok (analytics.tiktok.com), LinkedIn (px.ads.linkedin.com), ad-tech tags — each has a different endpoint grammar, so the capture helper must know them all. - GTM or hardcoded gtag? GTM means the truth flows through
window.dataLayer.pushfirst, then GTM fires the beacon. You may assert at the push layer (input contract) AND the beacon (output contract); they are different tests. - Is there a tracking plan? If not, build one first — it is the contract everything else validates against. No plan means no objective pass/fail.
- Consent platform and default consent state? Consent Mode v2 changes which beacons are even allowed to fire before consent. You need the CMP's accept/reject selectors to drive the test.
- Client + server (CAPI) dedup in play? If purchases fire both client Pixel and server Conversions API, the
event_idmust match or you double-count. This is the correctness property, not "did fbq run." - News-media surface? Article pages add article-view, scroll-depth thresholds (25/50/75/100), and paywall-meter events that generic e-commerce plans miss.
Core Principles
-
Intercept the beacon, never trust the DOM or
dataLayeralone. A button click that updates the DOM, or adataLayer.pushthat GTM silently drops, leaves no GA4 hit. The only proof an event was sent is the outbound request to the collect endpoint. Assert on the network beacon's URL params; readingwindow.dataLayerviapage.evaluateonly proves the push happened, not that anything left the browser. -
The tracking plan is a typed contract, not a comment. Every expected event lives in an external schema (JSON/YAML/TS interface) with required params and their types. Tests validate captured events against it and report
missingparams and typeviolations. Hardcoding one expected value inline asserts nothing about the other twenty params and rots on the first plan change. -
De-duplication is the real correctness property for purchases. Checking that
fbevents.jsloaded or counting thatfbq('track','Purchase')ran misses double-counting entirely. The property that matters: the browser Pixel and the server CAPI send the sameevent_id/eventIDso Meta collapses them into one conversion. -
Consent state is an input dimension. Test the approved regional policy in basic or advanced mode. Observe the application's actual four-signal default and updates; do not supply a default from the test. Basic mode blocks tags before consent, while advanced mode may emit permitted measurements without cookies. Assert the planned post-accept events and relevant storage independently.
-
Drive real user actions and wait on requests, never the clock. Scroll depth fires from actual scrolling (
mouse.wheel,scrollIntoView,evaluate(scrollTo)), and you wait for the beacon withwaitForRequest, notwaitForTimeout