Sub topic 8
Specifying Events and Metric Definitions for Engineering
Assume you understand product funnels, proportions, feature flags, and basic event tracking. This chapter focuses on turning an experiment brief into an implementation contract that engineering and data can use consistently.
Start with the metric, then define the events
A metric is a calculation over recorded events. Engineering needs more than a metric name. The team must agree on:
- The event that starts the measurement.
- The event that counts as success.
- The user or account population included.
- The time window for counting success.
- How repeated events, retries, cancellations, and errors are handled.
- Which timestamp determines eligibility and conversion.
For example, “checkout completion rate” could mean completed orders divided by checkout starts. It could also mean completed orders divided by users assigned to the experiment. Those definitions answer different questions.
| Item | Example definition |
|---|---|
| Population | Logged-in web users with a saved address |
| Denominator | Users assigned to a variant who open checkout |
| Numerator | Those users with a successful order within 24 hours |
| Exclusions | Test accounts, cancelled orders, duplicate order IDs |
| Attribution | The first eligible checkout after assignment |
Write definitions in plain language before selecting event names. This exposes disagreements while they are still inexpensive to fix.
Specify the event contract
An event contract is a shared description of an event, including its name, required fields, allowed values, and emission rules. The contract should identify the experiment assignment and a stable entity ID.
experiment: checkout_address_autofill
events:
- name: experiment_exposure
when: the checkout page renders after assignment is available
required_properties:
experiment_key: checkout_address_autofill
variant: control_or_treatment
user_id: stable_logged_in_user_id
assignment_id: id_for_this_assignment
- name: checkout_started
when: the user submits or opens the first checkout step
required_properties:
checkout_id: stable_checkout_identifier
user_id: stable_logged_in_user_id
- name: order_completed
when: payment succeeds and the order receives a confirmed status
required_properties:
order_id: unique_order_identifier
checkout_id: related_checkout_identifier
user_id: stable_logged_in_user_id
metric:
name: checkout_completion_rate
formula: unique order_completed users / unique eligible checkout_started users
conversion_window: 24 hours after checkout_startedThe experiment_exposure event should represent actual exposure, not merely assignment. A user assigned to treatment but blocked before the checkout page should not be counted as having seen the treatment.
Connect events to the data model
The data team should map each event to its source table or stream and document deduplication. Use stable identifiers so retries do not inflate counts. Define whether the metric uses unique users, sessions, checkouts, or orders. The unit in the numerator and denominator must match unless the difference is deliberate and documented.
Common implementation errors
- Emitting exposure before the variant is known.
- Logging assignment on the server but conversion only in the browser.
- Using local time in one event and UTC in another.
- Counting page loads instead of unique users.
- Omitting events when a payment retries or an order changes status.
- Including users who were assigned after they already entered the funnel.
- Renaming event properties without updating the analysis query.
A short implementation review should include product, engineering, and data. Test each variant manually, replay key failure paths, and verify that one real user produces the expected event sequence.
Exercise
A user is assigned to treatment but closes the page before checkout renders. Should this user count in the treatment conversion metric?
Show answer
Count the user in assignment-level analyses only if that is the planned estimand. For an exposure-based checkout metric, exclude the user because the treatment was never rendered, and document that rule in advance.