# Design: choosing a North Star metric for GitHub newcomers

Written and committed before any cohort query. The frozen definitions are in `protocol-r1.json`, the predictions in
`predictions-r1.json`; where this file and the protocol differ, the protocol wins.

## The question

A product team is told to pick one North Star metric and the input metrics under it. The usual first pick is a count
of actions per user ("events", "engagement"), because it is the number every event pipeline already has. This study
asks, for a product whose users are the people acting on GitHub in public: which candidate metric, measured in a
newcomer's first seven days, best predicts whether the newcomer is still active in week 13 (days 84 to 90), and which
first-week behaviours go with staying.

It could come out either way. A count of actions carries more information than a count of days, so it may predict as
well or better. Or it may be swamped by bursts (one afternoon of 300 pushes from a script) and rank the wrong accounts
first.

## Overlap test

The nearest published study, `web-funnel-by-source`, builds a purchase funnel by traffic source from a GA4 sample and
forecasts orders. It does not choose a metric, has no retention cohort and no BI tool. No published page answers this
question or uses this data.

## Data

- GH Archive hourly files, every public GitHub event: the same data as the BigQuery copy of the archive. The BigQuery
  sandbox credential on hand can read table metadata but cannot create query jobs (403, `bigquery.jobs.create`), so
  the files are downloaded one hour at a time, read with DuckDB, filtered to the new-account band and deleted.
- Measured from BigQuery table metadata (no query): each month of 2024 holds 138 to 166 million events and 367 to 463
  GiB; one hourly file is 70 to 140 MB compressed and about 275 thousand events.
- Bounded span: the threshold day 2024-09-09, the cohort day 2024-09-10, days 1 to 6 and days 84 to 90. 15 days, 360
  hourly files, about 100 million events read. The follow-up repeats the same span around 2024-10-15.

## Newcomers without the full history

A newcomer is usually "first event ever", which needs the whole archive. GitHub account ids are issued in increasing
order, so an account whose id is above the largest id active on the day before the cohort day was created after
that account. The band (t1, t2] is above the largest id seen on 2024-09-09 and at most the largest id seen on
2024-09-10. A cohort member is an account in the band with a public event on 2024-09-10. A dbt test checks that no
member has an earlier event in the data read.

## The model (dbt, DuckDB)

- `stg_events`: one row per event id (duplicates across hourly files dropped, counted), placed by `created_at`.
- `stg_hours`: one row per hourly file, with missing and short flags (under 40% of the window's median hour).
- `dim_day`, `dim_account` (cohort, first action, automation flags), `fct_account_day` (account by day).
- `mart_newcomer`: one row per cohort member, with the five candidates, six inputs, activation and retention.
- Every model is a table, so the same project runs on the BigQuery sandbox, which allows no DML. Tests: keys unique
  and not null, accepted values, relationships, the band test, the retention test, and a warning on short hours.

## Candidates, inputs, outcome

Five candidates over days 0 to 6: events, active days, distinct repositories, events on other people's repositories
(not stars or forks), stars. Six inputs: pushed to an own repository, created a repository, opened a pull request on
someone else's repository, opened an issue or commented on someone else's, forked, starred. Retained: any public event
other than a star on days 84 to 90. Automation (a `[bot]` login, more than 100 events in one hour, or more than 1000
in the first week) is excluded and counted.

## Scoring

AUC of each candidate for retention, with 1000 account-level bootstrap resamples (seed 20240910) for the interval of
each difference. Inputs: the retention difference standardised over active-day strata, beside the raw difference,
called an association. Funnel: day 0, a second day, activated, retained; the biggest drop is sized with the declared
assumption in the protocol. The default check compares the top decile by events with the top decile by active days.

## What would reverse the call

If events has an AUC within 0.01 of active days, or above it, on either cohort, the call to replace the action count
fails, and the dashboard leads with events. If the second cohort picks a different winner, the page says the choice is
not stable and recommends a holdout of both.

## The dashboard

Built on `mart_newcomer` and `dim_day`, for a product executive reading in a minute: the chosen North Star with its
week-13 retention curve, the candidates' AUC side by side, the funnel with the biggest drop, the inputs, and the data
census. Filters: first action and activation status. Shipped as a Tableau packaged workbook (Hyper extract written
with the vendor's Hyper API) and as a Power BI project (plain-text model with DAX measures and a report). The Tableau
Public link exists only once it is published from the desktop app.

## Limits declared now

One cohort day per run, a 24-hour cohort, one platform. Public events only: private work is invisible, so "retained"
means "still acting in public". Observational: inputs are associations. GitHub logins can be renamed; ids cannot,
so every join is on the id.
