# Web funnel by traffic source on a real GA4 export: design, round 1

Committed before any scored run on the export. The frozen parameters are in `protocol-r1.json`; where the two differ, the
JSON wins. Any later change is a labelled "Change N to the protocol", committed before it is used, and a change made after
results are seen says so.

## Question

On a real public ecommerce event export, where in the funnel does each traffic source lose buyers, how much of that is
real and how much is tracking, and how far do sessions by source forecast next month's orders? And when tagging is wrong,
what breaks, and does a schema audit notice?

## Overlap test (one question, one study)

- `event-contracts` asks which tracking breaks a pre-release contract stops, on a synthetic app, and its web round asks it
  of a synthetic site's data layer in a browser. Neither touches a real export. This study starts where those stop: the
  export a team already has. It links that round for the pre-release half and does not repeat it.
- `identity-resolution` asks how user counts and channel shares drift as identity signals disappear, on a synthetic shop.
  Here identity is taken as exported; the question is funnel loss, attribution rules and forecast.
- `order-value-change` asks whether average order value moved, on real wholesale orders. No funnel, no traffic.
- `marketplace-revenue-forecast` forecasts trips and revenue on public trip records. This study reuses only the idea of a
  plan-against-actual bridge, on different data.
- `flagship-gtm-funnel-analytics` is a synthetic B2B lead funnel. Different data, different unit (leads, not sessions), no
  event schema.

Different question and different data (a real web analytics event export), so it is a new study.

## Data

`bigquery-public-data.ga4_obfuscated_sample_ecommerce`, the obfuscated sample of the Google Merchandise Store's GA4 export:
92 daily tables, 2020-11-01 to 2021-01-31, read once to local parquet. The publisher states that the data is obfuscated and
that internal consistency may be limited. So every audit finding here describes this obfuscated sample. It can never say
how well the store itself is tagged. Raw rows are not redistributed: `tools/extract.py` re-reads them from the source.

Access note: the study reads rows with the table read call (`tabledata.list`), which creates no query job and scans
nothing. No query is run, so there is no dry run to report; the size guard is the tables' stated bytes, read from their
metadata first.

## Sessions and channels (rebuilt from raw events)

- Session key: `user_pseudo_id` plus the `ga_session_id` event parameter. An event with no `ga_session_id` belongs to no
  session and is counted by the audit.
- Session source and medium: from the session's earliest event carrying a `source` or `medium` parameter.
- Placeholder values: null, empty, `<Other>`, `(data deleted)`, `(not set)`.
- Channel (this study's own medium-based rule, simpler than any product's default grouping): any placeholder in source or
  medium is `unknown`; `(direct)` with `(none)` is `direct`; medium `organic` is `organic search`; medium `cpc`, `ppc`,
  `paid` or `paidsearch` is `paid search`; medium `referral` is `referral`; `email`, `e-mail` or `e_mail` is `email`;
  anything else is `other tagged`.
- Device: `device.category` on the session's first event.

## Audit (each check written before it runs)

Thirteen checks, in `protocol-r1.json`: session id and page parameters on every event; session start present; session
source and medium usable; user-level source usable; items on each ecommerce event; transaction id, value, currency and
revenue on purchases; duplicate transaction ids; item totals against revenue; funnel order inside a session; daily outages
of funnel events; sessions rebuilt three ways (session start count, user plus session id, a 30-minute inactivity gap).

Every check has a positive control in `tests/`, on a small made-up export with one planted fault per check.

## Funnel

Stages: session, product view (`view_item`), add to cart, begin checkout, purchase. A session reaches a stage if it holds at
least one such event. Rates per channel and device. Intervals: 95% percentile, Poisson bootstrap over users, 1,000
replicates, because sessions of one user are not independent. Cells under 200 sessions are shown as too small and carry no
reading.

Two reads, both reported: Read A takes the export as it is. Read B removes the events the audit flags: ecommerce events with
empty items, purchases with a missing or placeholder transaction id, purchases with no value or revenue, and the second and
later purchase events sharing a transaction id. Sessions with an unusable source stay, as channel `unknown`, in both reads.

## Attribution

Share of orders by channel under three rules, rebuilt from raw events: user first touch (`traffic_source.*`), session scope
(the session's own source), and last non-direct (the session's channel, or if it is direct or unknown, the user's latest
earlier session in the previous 30 days with a known non-direct channel). None of them is claimed to match any product's
reports: the publisher says the sample cannot be compared with the store's demo account.

## Forecast

Three months hold about two independent month-ahead tests, so this part is a description. It is not a ranking. Daily
orders from Read B; sessions by channel by session date.

- Month-ahead: 28-day horizon (four of each weekday), origins every 7 days at day index 28, 35, 42, 49, 56, 63: 6 origins,
  of which only 2 do not overlap. Models: `N28` (next 28 days equal the last 28), `N7` (4 times the last 7 days' orders), and
  the sessions model `S` (for each channel, 4 times the last 7 days' sessions times its order rate over the last 28 days,
  summed).
- Week-ahead: 7-day horizon, origins every 7 days from day index 28 to 84: 9 non-overlapping origins. Models `N7w` and `S7`,
  compared by a two-sided sign test. A regression on sessions was left out in advance: too few origins to fit one.
- Bridge: each month-ahead miss of `S` split by channel into traffic (actual minus forecast sessions, at the forecast rate)
  and conversion (actual sessions times the change in rate). The split closes by construction, so it is bookkeeping, used only
  to name the channel behind a miss.

## What breaks when tagging is wrong

Nine declared tagging faults (T1 to T9, `protocol-r1.json`) are applied to a copy of the real events; the same audit, funnel
and attribution then run on each copy. Reported per fault: change in orders, revenue, sessions, conversion, the largest
channel-share move, and which audit checks fired. A check fires when its rate rises by at least 0.5 points and at least 20%
of its baseline. Faults and checks have one author, so the catch count is a self-test and is never a headline.

## Predictions

Fifteen, with bands, in `predictions-r1.json` (P1 to P15). Each is reported as held, missed or untestable; P15 is a safe bet.

## Scope limits decided in advance

No independent fault author in this round. No tag container or data layer is built here; the event-contracts web round holds
that work. Only the event export is studied, so the page names GA4 and no other analytics or tag product.
