trackskew checks mobile analytics events against a versioned tracking plan. It validates every event's schema for the app version that sent it, drops exact retries and flags double-fires, estimates each device's clock offset and corrects it before rebuilding sessions, checks sequence rules (a server purchase needs an earlier client checkout, a session starts with app_open), and then compares violation rates between consecutive app versions on the same platform with exact tests under Benjamini-Hochberg control. A regression is reported against the release where it first appeared. All data in this repository is synthetic, produced by a seeded generator.
Each release of a mobile app can quietly break instrumentation: a property stops being sent on Android, a tap fires twice on iOS, a renamed event splits a funnel. Two things make this hard to see. Devices with wrong clocks stamp client events hours off, so a server-side purchase appears to happen before the client checkout_completed that caused it, and offline batches arrive hours after the events they carry. And a regression is only visible as a change in a rate between versions, among hundreds of (property, platform, version) combinations, so without multiple-comparison control the noise either hides the real problem or produces false alarms. The result is usually an impossible funnel noticed weeks later, with nobody sure which release started it.
flowchart LR
A[Raw events<br/>JSONL] --> B[Drop exact retries<br/>flag double-fires]
B --> C[Validate against<br/>versioned plan]
B --> D[Per-device clock<br/>offset, p95 of<br/>client minus server]
D --> E[Rebuild sessions<br/>30 min gap<br/>on corrected time]
E --> F[Sequence rules<br/>precedence, uniqueness,<br/>first event]
C --> G[Violation rates per<br/>check, platform, version]
F --> G
G --> H[One-sided Fisher test<br/>vs previous version<br/>Benjamini-Hochberg]
H --> I[Regression table<br/>q < 0.01 and rise >= 1 pt]
plan.py: YAML tracking plan (events, source, typed properties with enum and min/max,since/untilper event and property, sequence rules, funnel) and numeric semantic-version comparison.validate.py: violation codesunknown_event,missing_required,type_mismatch,enum_violation,out_of_version, plusout_of_rangefor min/max.dedupe.py: sameevent_idis a retry (first delivery kept); same device, name and properties within 1 s is a double-fire.skew.py: offset = 95th percentile ofclient_ts - server_tsover a device's client events; offsets beyond +/-60 s are corrected.sessions.py,rules.py,funnel.py: sessions on corrected time (client events on corrected client time, server events on server time), rules, and in-order funnel counts.releases.py,stats.py: cell counts, Fisher exact tests, Benjamini-Hochberg.generate.py: the seeded synthetic stream and its ground-truth sidecar.
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
trackskew generate --seed 13 # writes .tmp/events.jsonl, .tmp/events.truth.json, .tmp/plan.yaml
trackskew validate .tmp/events.jsonl --plan .tmp/plan.yaml
trackskew skew .tmp/events.jsonl
trackskew releases .tmp/events.jsonl --plan .tmp/plan.yaml # add --all for every tested cell
trackskew funnel .tmp/events.jsonl --plan .tmp/plan.yaml --raw # or --corrected (default)
python scripts/demo.py # all of the above in one run
pytest -qgenerate accepts --out, --devices (default 3000) and --days (default 30). The event file has one JSON object per line: event_id, device_id, platform, app_version, name, source (client or server), client_ts (null for server events), server_ts (epoch seconds) and props.
The synthetic stream has about 121,000 events from 3,000 devices over 30 days, with planted defects (listed in .tmp/events.truth.json). Output of python scripts/demo.py:
synthetic stream: 121038 events, seed 13
exact retries dropped: 1193
double-fires flagged: 710
schema violations: 2177
== Clock skew ==
devices: 2998 with an estimate: 2941 corrected: 120
offset over estimated devices: min -900.4s median -0.2s max 7199.8s
offset bucket devices min (s) max (s)
------------- ------- ------- -------
-900s 30 -900.4 -900.2
+7200s 90 7199.4 7199.8
largest error against the 120 planted offsets: 0.63s
== Release regressions (one-sided Fisher, BH, q < 0.01, rise >= 1 point) ==
cells tested: 390
check platform version previous rate new rate q-value
------------------------------------------ -------- ------- ------------- -------- ---------
checkout_started.currency:missing_required android 5.3.0 0.1% 100.0% <1e-300
promo_banner_tap:out_of_version android 5.3.0 0.0% 100.0% 8.47e-146
promo_banner_tap:out_of_version ios 5.3.0 0.0% 100.0% 9.68e-158
add_to_cart:double_fire ios 5.3.1 0.0% 29.4% 9.74e-244
== Funnel, sessions reaching each step ==
step raw corrected difference
------------------ ----- --------- ----------
app_open 33161 33161 +0
product_view 26573 26573 +0
add_to_cart 14315 14315 +0
checkout_started 8565 8565 +0
checkout_completed 6000 6000 +0
purchase 5793 6000 +207
sessions rebuilt: 33161
precedence violations after correction: 0
precedence violations before correction: 207
A q-value of <1e-300 means the Fisher p-value underflowed double precision to 0, so only a bound is printed. The double_fire rate is per delivered event: 40% of taps produce a second event, so about 0.4 / 1.4 of iOS 5.3.1 add_to_cart events are the repeat. The promo_banner_tap cells are 100% because every event still using the old name in 5.3.0 is out of version.
- Upper-tail offset estimate. A device with clock offset
oreportsclient_ts - server_ts = o - delay, and delay (network latency or time in an offline queue) is never negative. The 95th percentile of the difference is therefore the least-delayed sample, and offline batches only push the estimate's inputs down. A median would read a device with half its events uploaded 4 hours late as 4 hours slow; the p95 does not, and the tests check that. The cost is that a device whose every event was uploaded late cannot be told apart from a slow clock, so devices need at least 8 client events and a share of events sent promptly. The estimate is also biased low by the smallest network latency, about 0.2-0.6 s here, far below the 60 s correction threshold. - Cell-level multiple testing. Every (check, platform, version) cell with data in both the version and its predecessor is tested, including checks that never fire, so the family is the 390 things that were looked at. Benjamini-Hochberg controls the false discovery rate without the power loss of Bonferroni across hundreds of cells. A regression must also rise by at least 1 percentage point, because with enough events a 0.1-point change is significant and not worth a page. Cells with no events on either side are not tested, so a renamed event shows up through its
out_of_versioncheck, not as a rate on a name that has no predecessor. - Rates per delivered event. Property checks divide by events of that name after retries are removed, double-fired copies included, so a copy carries the same defects as the tap it duplicates. Sequence rules divide by what they examine: purchases for precedence and uniqueness, sessions for the first-event rule. The alternative, dividing by taps, needs a definition of a tap that the raw stream does not have.
- Time per source. Client events are placed on the device clock minus the device's offset; server events keep server receive time. Precedence compares the two on that common axis, which is why it only holds after correction. Double-fire detection stays on the device's own clock, so skew cannot hide it.
- Background noise includes required properties. The generator drops 0.3% of property values at random,
order_idexcepted since it is an identifier, so there are about 100missing_requiredcells with a nonzero background rate for the tests to prove are not flagged. Dropping only optional properties would produce no violations at all. - Rows are not independent. The Fisher tests count events as if they were independent, but events cluster by device, so a few heavy devices can dominate a cell and the q-values are optimistic for such cells. The planted regressions here are platform-wide, so the calls do not depend on it.
- Plan
sourceis not enforced. The plan records whether an event is client or server, which the generator and the sequence rules use, but validation does not report an event whose actual source differs, so a client-sentpurchaseis not a violation. - Session starts are spaced. The generator starts each session in the first 20 minutes of an hourly slot, so planted sessions are always more than the 30-minute gap apart and rebuilt sessions match them one to one (a test checks this). Real traffic has no such guarantee.
- Malformed versions. An
app_versionthat is notmajor.minor[.patch]stops the run with a one-line error naming the event, instead of a traceback. - Plan semantics.
sinceanduntilare inclusive. A property sent outside its window isout_of_version; a property is only required in versions where it applies. Properties the plan does not mention are ignored. Versions insinceanduntilmust be quoted strings: YAML reads an unquoted5.10as the float 5.1, so the loader rejects it instead of silently turning it into 5.1.0.
83 tests, about half a minute on a laptop (pytest -q). They cover version ordering and plan validation (including rejection of unquoted since/until versions), a hand-built six-event schema fixture, retry and double-fire handling, offset estimation on hand-built devices and on the planted ones (within 5 s of +7,200 s and -900 s; offline devices with correct clocks stay under 60 s and are not corrected), session boundaries, the sequence rules (precedence violations on 2-hour-fast devices are above 0 before correction and exactly 0 after), Fisher/BH behaviour on hand-computed values (a 10 p-value fixture), recovery of the planted release regressions with nothing else flagged, deterministic and sorted CLI output (the CLI tests share one pipeline run per module), and generator reproducibility.
src/trackskew/
plan.py validate.py dedupe.py skew.py sessions.py rules.py
releases.py stats.py funnel.py pipeline.py
events.py generate.py report.py cli.py
data/plan.yaml tracking plan used by the generator and the demo
scripts/demo.py end-to-end run that prints the tables above
tests/ pytest suite
MIT. See LICENSE.
