Statistics

Randomization Unit: User, Session or Pageview

The randomization unit decides what your A/B test can measure and how much sample you truly have. How to pick it without inflating your own p-value.

Flat illustration of two long rounded containers stacked vertically, each holding a grid of small dots, in deep forest green and mint tones

The randomization unit is the level at which assignment to control or treatment happens, and it settles two things at once: what kind of effect your test can detect, and how much statistical sample you actually hold. Switching units is not an implementation detail, it is a trade between power and validity, and the version that produces the prettiest p-value is almost always the wrong one. This guide covers the difference between randomization unit and analysis unit, a worked example where the same experiment reports z of 3.680 or 6.374 depending on which unit you read it in, the design effect that explains the gap, and a decision rule for choosing among user, session, pageview and cluster. It is part of our complete guide to A/B testing and continues the reasoning from ratio metrics in A/B testing.

Every test carries two units

Every online experiment has two different units, and most confused arguments about results come from treating them as one.

Deng, Knoblich and Lu define both precisely in their KDD 2018 paper on the Delta method in metric analytics. The randomization unit is the granularity level where sampling or randomization is performed. The analysis unit is the aggregation level of metric computation. Analysis is straightforward, the authors note, when the two agree, for example when randomizing by user while also computing average revenue per user.

Trouble starts when they diverge, which is more common than it sounds. The authors report that for the same experiment there are usually metrics with different analysis units: most user-randomized experiments run by Microsoft’s experimentation platform contain both user-level and page-level metrics.

There is one hard constraint on the relationship, and it is the first thing to understand before picking any unit. The randomization unit cannot be more granular than the analysis unit. The authors spell out why: if it were, the analysis unit would contain observations under both treatment and control, nullifying the purpose of differentiating the two groups. Randomize by pageview and then report “conversion rate per user” and nearly every user will have seen both sides, so the measured gap between arms shrinks by construction, not because the effect is absent.

Unit hierarchy and where the assignment line can fallThree stacked levels of granularity. At the top, two users, each drawn as a wide rectangle. In the middle, three sessions inside each user. At the bottom, several pages inside each session. A dashed cut line marks the assignment level at the top, showing whole users going to one arm or the other while sessions and pages inherit the assignment from above. A warning note indicates that the assignment line cannot sit below the unit the metric uses as its denominator.The assignment line drops only as far as the metric allowsuserassigned to Bassigned to Asessionpageassignment lineAssign at the top and every session and page inherits the user’s arm: the experience stays consistent.Drop the line to the page and still report per user, and the same user sits in both arms, erasing the effect.The metric sets the floor: the randomization unit can never be finer than its denominator.
The hierarchy is always the same. What changes from test to test is the height at which the assignment line is drawn, and that height has consequences that show up in the report.

Worked example: one test, two readings

A shop runs a test randomized by user. That is 100,000 users per arm, and each user averages 3 sessions over the period. The metric of interest is “converted at least once”.

Paste the numbers below into the calculator to reproduce the arithmetic line by line.

Statistical significance calculator
Control (A)
Variation (B)
Control (A) · Rate-
Variation (B) · Rate-
Relative lift-
p-value-
95% CI of the difference-

Two-sided two-proportion z-test. "Not significant" almost always means not enough sample, not that the versions are equal.

First, the correct reading, with the analysis unit matching the randomization unit:

Read per user Users Conversions Rate
Control 100,000 12,000 12.000 percent
Treatment 100,000 12,540 12.540 percent

On screen, the calculator shows rates of 12.00 and 12.54 percent, a lift of plus 4.5 percent, a p-value of 0.0002 and a 95 percent interval of plus 0.3 to plus 0.8 percentage points, with B as the winner. The interface rounds its display and does not show the z score, so the engine’s exact figures, the ones used throughout this article, are: plus 0.540 percentage points, plus 4.500 percent relative, z = 3.680, a p-value of 0.00023 and an interval of plus 0.252 to plus 0.828 percentage points. A solid, unspectacular result.

Now the same experiment read per session. With 3 sessions per user, the dashboard shows 300,000 sessions per arm, and the conversion rate per session is identical:

Read per session Sessions Conversions Rate
Control 300,000 36,000 12.000 percent
Treatment 300,000 37,620 12.540 percent

The calculator shows the same rates and the same plus 4.5 percent lift, and the p-value drops into the band it displays as less than 0.0001. At full precision: the same plus 4.500 percent relative lift, z = 6.374, a p-value of 0.00000000018 and an interval of plus 0.374 to plus 0.706 percentage points. Nothing about the experiment changed. The only move was swapping the metric denominator from user to session.

The ratio between the two z values is exactly the square root of 3, the number of sessions per user: 6.374 divided by 3.680 gives 1.7321. That is not a coincidence, it is the signature of a standard error computed as if every session were a fresh independent observation.

The design effect: how much sample is real

Sessions from the same user are not independent. Someone who buys on one visit tends to buy on another; someone who never converts tends to never convert. The quantity that captures this is the intra-cluster correlation, defined in Deng, Knoblich and Lu as the contribution of between-cluster variance to total variance.

For equal cluster sizes the authors record the closed-form variance, and out of it comes the factor known as the design effect: 1 plus the intra-cluster correlation times the cluster size minus 1. They lay out both extremes clearly. When within-cluster variance is zero, every observation in a cluster is identical, the intra-cluster correlation equals 1, and variance depends only on the number of clusters. When between-cluster variance is zero, the observations really are independent, the correlation equals 0, and the formula collapses to the simple case.

Applied to our test, with clusters of 3 sessions per user:

Intra-cluster correlation Design effect Corrected z p-value Effective sessions per arm
0.00 1.000 6.374 0.00000000018 300,000
0.25 1.500 5.205 0.00000019 200,000
0.50 2.000 4.507 0.0000066 150,000
0.60 2.200 4.298 0.000017 136,364
1.00 3.000 3.680 0.00023 100,000

Look at the last row: with intra-cluster correlation of 1 the corrected z lands back on exactly the 3.680 of the per-user reading, and effective sample lands back on exactly the 100,000 users. The formula degrades to the right answer, which is a useful sanity check.

And look at what it is really saying. Those 300,000 sessions were never worth 300,000 units. They are worth somewhere between 100,000 and 300,000, depending on how much of the behavior belongs to the user and how much belongs to the visit. An extra session from the same visitor is not fresh sample, it is partially repeated information.

Effective sample per arm as intra-cluster correlation risesFive horizontal bars drawn to scale representing effective sessions per arm. At intra-cluster correlation zero the bar spans the full width, standing for 300 thousand sessions. As correlation rises through 0.25, 0.5, 0.6 and 1, the bars shorten to 200 thousand, 150 thousand, 136 thousand and 100 thousand, until they match the number of users actually randomized.Nominal sessions: 300,000. Sessions the test actually uses: it dependsrho 0.00300,000rho 0.25200,000rho 0.50150,000rho 0.60136,364rho 1.00100,000 (equals the user count)The orange line marks the floor: the number of units that were actually randomized.No choice of denominator can manufacture more information than the assignment created.
Counting sessions does buy something, but always less than the ratio of counts, and the gain shrinks fast as correlation rises.

An honest caveat from the authors themselves: this closed form, while theoretically sound, has only limited practical value, because it assumes every cluster shares the same size and the same distribution, which never holds in production. Users make wildly different numbers of sessions. Their proposed answer is the Delta method applied directly to the metric definition as a ratio of two averages of randomization-unit quantities, the same logic behind our treatment of ratio metrics.

It is worth knowing how large the error is when you ignore this. In the simulation published in that paper, with a thousand clusters of heterogeneous sizes, the true standard deviation of the estimator was 0.00895 while the naive standard error came out at 0.00522, roughly 42 percent below the truth. The Delta method returned 0.00908, close to the real value.

How to choose the randomization unit

The choice is not a matter of technical taste, it is a sequence of constraints. Walk them in order.

Decision tree for choosing the randomization unitA flow of four questions in sequence. The first asks whether exposure leaks beyond whoever was assigned; if yes, the unit is a cluster, region or time block. The second asks whether a stable user identifier exists; if not, the unit is session or device, with the caveat that the measurable effect is confined to a single visit. The third asks whether the effect depends on consistency or accumulation across visits; if yes, the unit must be user. If none of the above forces a choice, the default answer remains user.Four questions, in order. The first yes decides.1. Does exposure leak beyond who was assigned?cluster, region or time block2. Is there a stable user identifier?no: session or device, with caveats3. Does the effect need cross-visit consistency?user, no exceptions4. None of the above forces a choice?user, by defaultQuestion 2 is the only one that pushes down the hierarchy, and it is an infrastructure limit,not a design choice. Questions 1 and 3 push up, and they push for reasons of validity.None of the four questions is “where do I get the smaller p-value”.
Notice that the hunt for statistical power never enters the tree. Power is a consequence of the unit you choose, never a criterion for choosing it.

The options in detail:

Randomization unit When it is right What you give up
User (cookie, account, device) Default. Any change a visitor could notice across visits Nothing, beyond needing a stable identifier
Session The change lives inside one visit and leaves no memory, or no stable identifier exists Cross-visit consistency, and any effect that accumulates
Pageview Almost never, in product testing Consistency inside a single visit; it contaminates the reading
Account or organization B2B products where colleagues cannot see different screens Power, because the account becomes the cluster
Geographic region Interventions that cannot be delivered per user, such as offline media A great deal of power, see geo experiments
Time block Marketplaces with supply shared between arms Power, plus the need to handle time dependence, see switchback experiments

Two rows deserve a footnote. Deng, Knoblich and Lu cite as real reasons for cluster randomization both enterprise policy prohibiting users within the same organization from getting different experiences, and the need to reduce bias in the presence of network interference, which is precisely the problem covered in interference between variants.

What moving up the hierarchy costs in sample

Moving the randomization unit up costs power, and you can price it before you start. With a 12 percent baseline and a minimum detectable effect of 4.5 percent relative, the sample size engine returns 57,948 users per variant at 95 percent confidence and 80 percent power.

Randomizing by session instead would nominally require that same count in sessions, which looks 3 times cheaper. But those correlated sessions are not worth one unit each. Applying the design effect to the requirement:

Scenario Units needed per variant Equivalent in users
Randomize by user 57,948 users 57,948
Randomize by session, intra-cluster correlation 0 (unreal) 57,948 sessions 19,316
Randomize by session, intra-cluster correlation 0.25 86,922 sessions 28,974
Randomize by session, intra-cluster correlation 0.50 115,896 sessions 38,632

The discount is real, but it is smaller than the count ratio and it shrinks fast as correlation climbs. More importantly, the discount only holds if the effect you want to measure fits inside a single session. If it does not, you are not saving sample, you are measuring something else.

When session randomization is legitimate

There is an honest case, and it deserves naming so session assignment does not read as automatic malpractice:

Outside those cases the price is steep. Session randomization means the same visitor sees control on Monday and treatment on Wednesday, and any effect that depends on recognition, habit or learning gets diluted across arms. It also means contamination: part of arm A’s experience already sits in the head of the person being measured in arm B. The close relative of this problem shows up in the novelty effect in A/B testing.

Checklist before you launch

  1. Is the randomization unit written down anywhere? If nobody wrote it, nobody will check it when the results come in.
  2. Does the primary metric use that same unit in its denominator? If not, the confidence interval needs the Delta method or a design-effect correction.
  3. Is the randomization unit equal to or coarser than the analysis unit? Never finer.
  4. Is the unit identifier stable for the whole test? A rotating cookie silently converts user randomization into session randomization.
  5. Does the split per arm match the plan in the assigned unit? Check it with the SRM checker, in the right unit.
  6. Does the report show which unit each number was computed in? Two metrics in different units on the same table need labels.
  7. Was the power calculation done in the assigned unit? Not in the most numerous one.

Common mistakes

Make this automatic with Donnu

The expensive mistake here is not picking the wrong unit at the start. It is picking one unit at the start and reading the result in another at the end, with nothing in the report flagging the swap.

In Donnu, the randomization unit is part of the experiment declaration, and every metric in the report carries the label of the unit its denominator was computed in. When the denominator is finer than the assigned unit, the dependence warning sits next to the confidence interval instead of hiding in a footnote. And if you want to redo any of the arithmetic by hand, the p-value calculator and the sample size calculator take raw counts in whichever unit you choose.

References

Read next: Ratio metrics in A/B testing · Interference between variants · Switchback experiments · Sample ratio mismatch · Triggered analysis and dilution · P-value calculator · Leia em português

Frequently asked questions

What is the randomization unit in an A/B test?
It is the level of granularity at which assignment to control or treatment happens. Deng, Knoblich and Lu define the randomization unit as the granularity level where sampling or randomization is performed, and the analysis unit as the aggregation level of metric computation. In practice, the randomization unit is whatever gets assigned to one arm and stays there: a cookie-identified user, a session, a device, an account, a region or a block of time.
What is the difference between randomization unit and analysis unit?
The randomization unit is what the coin flip assigns; the analysis unit is what the metric counts in its denominator. When they agree, analysis is straightforward, for example randomizing by user and computing average revenue per user. When the metric denominator is finer than the assigned unit, such as randomizing by user and measuring click-through rate per page, every assigned unit becomes a cluster of correlated observations, and a standard error computed as if they were independent comes out smaller than the truth.
Can I randomize by session instead of by user?
You can, and sometimes it is the right call, but the price is steep and has to be paid knowingly. Randomizing by session means the same visitor sees control on one visit and treatment on the next, which destroys any effect that depends on consistency or accumulates across visits, and contaminates the reading through leakage between arms. Session randomization makes sense mainly when the change under test lives entirely inside one visit and leaves no memory, or when no stable user identifier exists.
Can the randomization unit be finer than the analysis unit?
No. Deng, Knoblich and Lu are explicit: the randomization unit cannot be more granular than the analysis unit, because the analysis unit would then contain observations under both treatment and control, nullifying the purpose of differentiating the two groups. Randomizing by pageview and then reporting a per-user metric means nearly every user sits in both arms, and the measured difference shrinks toward zero by construction rather than by absence of effect.
How do I correct the p-value when analysis is finer than randomization?
By estimating the design effect and inflating the variance by it. For equal cluster sizes the factor is 1 plus the intra-cluster correlation coefficient times the cluster size minus 1, where the intra-cluster correlation measures how much of total variance comes from between-cluster variance. The authors themselves warn that this closed form has only limited practical value because it assumes equal cluster sizes, which never holds in production; their proposed answer is the Delta method applied directly to the metric definition.
Does randomizing by session give more statistical power than randomizing by user?
Less than the raw counts suggest. Sessions outnumber users, but sessions from the same visitor are not independent, so each extra session is worth less than a fresh unit. In the limit where behavior is entirely a property of the user, the gain is zero: effective sample collapses back to the number of users. Real power sits between those extremes and depends on the intra-cluster correlation in your own data, not on a generic reference value.