Chapter 1 — Anatomy of Metrics

What Exactly Are We Counting?

14 min

Before you count, look inside the box

You're about to count users. Don't rush. First answer this: what in this archive actually represents a user? — QUERY

A cadet studies a hologram showing the same events grouped as individual actions, users, sessions, and orders, while a robot cat watches from the side.
Until you specify what you're counting—an event, user, session, or order—the number means nothing: the same data gives you four different counts.

Kotomarket's black box isn't a “users” table or a “metrics” table. It's an event log: a long list of rows, each one recording that something happened at a particular time.

Here are nine rows from a single day—March 14:

timeuser_idsession_ideventproperties
09:12:044412s-101app_opensource=push
09:12:314412s-101product_viewitem=bowl
09:13:024412s-101product_viewitem=scratching post
09:13:404412s-101add_to_cartitem=scratching post
09:20:117781s-102app_opensource=direct
09:21:557781s-102product_viewitem=bed
14:02:094412s-140app_opensource=direct
14:03:444412s-140purchasesum=$12.90
21:47:009003s-166app_opensource=ads

Each column answers a different question:

  • time — when it happened. You can use event time to define periods such as a day, week, or month;
  • user_id — who performed the action. The same user keeps the same id across all their visits;
  • session_id — which visit the action belongs to. A new session gets a new id;
  • event — what the user did;
  • properties — details about that specific action: where the user came from, which product they viewed, or how much they spent.

The main idea to remember is that metrics are not stored in the black box. It stores events and their attributes. A metric is an instruction for turning the event log into a number. The analyst defines the instruction, and the result depends on the counting rules.

An event is one line of the log4412product_view19:00:12812|||whouser_idwhentimestampwhat they dideventwith which objectproduct_idevent = who · what · when · with which object
The anatomy of an event: who did what, when, and during which session. These fields let you group and count events in different ways to calculate metrics.

Same data, four different answers

Take the same nine rows and ask four simple questions.

How many events? Nine—one per row. This is the most straightforward count: the number of records in the log.

How many users? Three—4412, 7781, and 9003. User 4412 appears six times in the log, but they're still one user. Here we deduplicate by user_id.

How many visits (sessions)? Four—s-101, s-102, s-140, s-166. User 4412 visited twice: once in the morning and once in the afternoon.

How many orders? One—there is exactly one purchase event in this data.

9 events → 4 sessions → 3 users → 1 order

Nine, four, three, one. The data didn't change; the counting unit did. None of these four numbers is more correct than the others because each answers a different question.

This gives you your first professional habit: whenever you hear a number, ask what unit it represents. “We have forty thousand”—forty thousand what: events, people, visits, purchases? In the Kotomarket example, nine events become one purchasing customer only after we change the question and the counting method.

Entry No. 2 in L.'s log:

For six months, the council was shown “activity” counted as events and compared with the number of customers in billing. Nobody noticed they were dividing apples by kilometers. The “events per customer” ratio kept rising, so everyone celebrated higher engagement. It turned out that for some users, the app was restarting by itself.

For a log like this, keep one sanity check in mind: over the same period, there can't be fewer events than sessions, or fewer sessions than users, provided every event belongs to a session and every user has at least one session. If a report shows more “users” than “events” under those conditions, that's a sign to check the calculation.

A metric definition has four parts

A metric isn't just its name. The name is the label on the jar; the definition tells you what's inside. A complete definition answers four questions:

  1. Object — what are we counting as individual units: users, sessions, orders, events?
  2. Event — what must happen for the object to be counted: open the app, view a product, make a payment?
  3. Period — what time window are we using: a calendar day (and in which time zone?), a calendar week, the last 7 days?
  4. Counting method — do we count unique objects or every match? Do we sum, average, or calculate a share?

Here's a complete definition worth getting used to:

DAU = the number of unique user_id values (object) with at least one app_open event (event) during a calendar day in Miami time (period), with each user counted once (counting method).

Long? Yes. But a definition this precise lets two different people calculate the same number.

Unique users vs. event count

The most common mix-up happens in the fourth part. Compare these two definitions for the same day:

definitionMarch 14
number of app_open events18 400
number of unique users with app_open4 200

Both numbers are valid and both come from the same log, but they differ by about 4.4×. They also react differently to changes in the data: if a bug makes the app restart and record extra app_open events, the first number will rise while the second won't. The first tells you how many times the event happened; the second tells you how many different users performed it.

Rule: whenever you hear “how many users do we have,” mentally add the word unique—then check that the calculation actually counts them that way.

Why two analysts get different numbers

Entry No. 5 in L.'s log. A manager asks two analysts for “the number of active users in March.” They come back with two answers: 41 200 and 33 900. Both calculated carefully, and neither made an arithmetic mistake. Their definitions differed here:

part of the definitionfirst analystsecond analyst
objectunique user_idunique user_id
eventany event in the logonly app_open
periodMarch 1–3130 days ending March 31
counting methoduniqueunique

The difference is 7 300 people, or about 18% of the larger value. There's no point arguing about who is right: both calculations follow their definitions. The question was incomplete.

Look at where the definitions diverged: the second and third rows. The first analyst counted anyone as active if they left any trace at all, including users who simply received a push notification whose delivery the system recorded. The second required an intentional app open. They also used different windows: the first used 31 calendar days, while the second used 30 consecutive days ending March 31.

A typical beginner mistake is assuming the definition is “obvious” and hesitating to ask for clarification. In practice, asking “Who exactly counts as active, and over what window?” shows professional judgment. The mistake is silently choosing your own definition and handing over a number without explaining what it means.

Here's an investigator's rule you'll use throughout the rest of the course:

Before you calculate anything, write the definition in one sentence—object, event, period, counting method—and show it to the stakeholder. Five minutes spent agreeing on the definition can save a day of rework and prevent a conclusion based on a different definition of the metric.

If the number goes into a report, include the definition with it as a footnote under the table. A month later, you may not remember exactly what you meant either.

The investigator's calculator. In this chapter, the runner really is a calculator: variables, arithmetic, and print. Below are the March 14 log totals counted using four different units. Run it, then change the numbers and watch how the ratios change.
python
Practice: write the code
The March 14 totals are already stored in variables. Calculate two ratios an analyst would check first: events per user (events_per_user) and sessions per user (sessions_per_user). Both use simple division; no rounding is needed.
python
Practice: write the code
A March 14 report says, “buyers — 1 284.” In reality, 1 284 is the number of purchase events, while there are 1 050 unique user_id values among them. Calculate by how many people the report overstated the number of buyers (overcount) and how many orders there are per buyer (orders_per_buyer).
python
Check yourself
A one-day log has 9 rows: cat 4412 generated 6 events across two sessions, cat 7781 generated 2 events in one session, and cat 9003 generated 1 event in one session. How many users and how many visits are there?
Check yourself
A stakeholder asks, “Count active users for the week.” What should you ask first so you don't have to recalculate the metric later?
Key takeaways
  • the black box contains events, not metrics; a metric is an instruction for turning the log into a number
  • the same rows produce different numbers depending on the counting unit: events, visits, users, orders—always clarify which unit the number represents
  • a metric definition has four parts: object → event → period → counting method
  • unique users and event counts are different metrics; one user can generate multiple events
  • if the definition isn't fixed, two analysts can calculate the same metric differently and get different numbers

Next comes our first real metric: DAU. We'll build it from these four parts and see how the same word, “active,” can produce three different answers.