# Measurement framework, event taxonomy and data layer specification

Fernhollow is a fictional company: software that keeps calibration records for laboratories, sold to labs of 10 to 500
people through a demo with sales. The site has a home page, three articles in a resources section with client-side
routes, a pricing page, a demo form and a gated guide. This file is the written standard the site's tracking is held to.

## From business question to event

| Business question | Who asks | KPI | Read from |
|---|---|---|---|
| Is the site reaching people at all? | Marketing lead | Visitors a day | `page_view` |
| Do they read, or leave? | Content lead | Pages per visitor | `page_view` |
| How much sales demand does the site make? | Revenue lead | Demo requests a day | `demo_request` |
| Does the pricing page move people to talk to sales? | Marketing lead | Pricing to demo conversion | `page_view` on pricing, `demo_request` |
| Are paid campaigns earning their budget? | Paid media lead | Paid share of demo requests | `demo_request.channel` |
| How large is the demand? | Revenue lead | Pipeline value a day, US$ | `demo_request.annual_value` |
| Does content make leads? | Content lead | Guide leads a day | `asset_download` |

## The seven metrics

Each is computed on landed hits, one row per `event_id`, with one typed column per property: a value of another type
lands as null in the metric's column.

- **Visitors**: distinct `visitor_id` with a `page_view`.
- **Pages per visitor**: `page_view` rows over visitors.
- **Demo requests**: `demo_request` rows.
- **Pricing to demo conversion**: of the visitors with a `page_view` whose `page_type` is `pricing`, the share with a
  `demo_request`.
- **Paid share of demo requests**: `demo_request` rows with `channel` equal to `paid`, over all `demo_request` rows.
- **Pipeline value**: the sum of `annual_value` on `demo_request` rows, in US dollars.
- **Guide leads**: `asset_download` rows.

People who reject or ignore the consent banner are not measured, so every metric covers consented visitors only.

## Event taxonomy

Names are `object_action` in lower snake case. Every event carries `event` and a unique `event_id`. Unknown properties
are a violation: a new property or event is added here and to the schema first, in the same change as the code.

| Event | When it fires | Required parameters | Allowed values |
|---|---|---|---|
| `page_view` | Every page load and every client-side route change, once | `page_path`, `page_type`, `channel`, `campaign_source`, `campaign_medium`, `campaign_name` | `page_type`: home, pricing, demo, thanks, guide, download, resources, article. `channel`: direct, organic, paid, email, other |
| `cta_click` | A tracked call to action is clicked | `cta_id`, `page_type` | `cta_id`: nav_demo, sticky_demo, home_pricing, home_resources, pricing_talk |
| `plan_selected` | A plan button is clicked | `plan_id`, `billing_period`, `annual_value`, `currency` | `plan_id`: starter, growth, enterprise. `billing_period`: annual, monthly. `annual_value`: a number from 0 to 100,000, the year's price in whole dollars. `currency`: USD |
| `form_start` | First focus inside a form | `form_id` | demo_request, asset_download |
| `form_error` | A submit fails validation | `form_id`, `field` | `field`: work_email |
| `demo_request` | A valid demo form is submitted, once however many times the button is pressed | `form_id`, `lead_id`, `company_size`, `plan_id`, `annual_value`, `currency`, `channel`, `campaign_source`, `campaign_medium`, `campaign_name` | `company_size`: 1-49, 50-199, 200-500. `plan_id` also allows undecided, with `annual_value` 0 |
| `asset_download` | A valid guide form is submitted, once | `form_id`, `lead_id`, `asset_id`, `channel`, `campaign_source`, `campaign_medium`, `campaign_name` | `asset_id`: record-keeping-guide |
| `consent_update` | The visitor decides, and on each later page load once a choice is saved. It controls the tags and never becomes a hit | `consent_state` | granted, denied |

The machine-readable versions are `site/spec/datalayer.schema.json` (every object pushed to the data layer) and
`site/spec/hit.schema.json` (the fields a hit adds).

## Data layer rules

- The site reports through one array, `window.dataLayer`, through `fhPush`. Pages never call the collection endpoint.
- The data layer describes what happened in the visitor's terms and holds no personal data. The email address stays in
  the form; the lead tags take only the part after the @.
- Campaign values come from the URL's `utm_source`, `utm_medium` and `utm_campaign` on the first page of a session and
  stay for the whole session. With no campaign, a referrer means `organic` and no referrer means `direct`.
- `annual_value` is a number, never text, and it is the price for a year.

## Tag layer rules

- The tag layer (`site/js/tags.js`, configured by `site/js/tag-config.js`) is the only code that sends hits.
- It holds events until the visitor decides. On `granted` it sends what it held and everything after. On `denied` it
  drops what it held and sends nothing. No decision means nothing is sent.
- Each hit carries `visitor_id` (one per visitor, from a first-party cookie set after consent), `session_id` and `ts`.
- One event makes one hit, with the event's `event_id`.

## How changes reach the site

| Channel | What it is | Who ships it |
|---|---|---|
| `site_build` | Anything in the site's code, through the site's build and deploy | Web engineers |
| `tag_publish` | A change to the tag configuration, published on its own with no site release | Marketing operations |
| `edge_rule` | A redirect or routing rule changed in the content delivery network's console | Web engineers or marketing operations |
| `vendor_script` | The consent banner's vendor updates its script; nobody here ships anything | The vendor |

## Traffic

About 1,400 visitors a weekday and a third of that at weekends: 40% from search, 30% direct, 20% from paid campaigns
through the redirect `/go/spring-demo`, and 10% from a newsletter. 30% are on phones. 60% accept the banner, a quarter of
those only after several seconds; 25% reject and 15% ignore it. About 28 demo requests a day. All of this is synthetic.
