Sub topic 11
Testing and iterating
This chapter covers how to test changes to a referral program or recommendation placement and decide what to keep. It assumes you can read basic Python and SQL, and that you know the earlier chapters' terms: k-factor, attribution, confirmed signup, and subscriber quality by source. No statistics background beyond "a percentage has noise" is needed.
Why growth tactics need controlled tests
Newsletter growth is noisy. A referral reward change in March may coincide with a viral post, a holiday, or a recommendation partner's big send. If you compare "before" and "after," you measure all of those together.
A controlled test (an A/B test) fixes this. You split eligible people randomly into two groups at the same time. One group sees the current version (control) and the other sees the change (variant). Because both groups live through the same weeks and events, the remaining difference is attributable to your change.
You can test many things in this program:
- The wording and placement of the "share this newsletter" block.
- The reward threshold, for example 3 referrals versus 5 for the first reward.
- The blurb and image your publication shows in a recommendation network.
- The landing page that referred visitors see.
- The timing of a reminder email to subscribers who have not shared.
The testing loop
Treat each test as one turn of a loop. You write down a hypothesis, choose a metric, size the test, run it, and decide. Then the result feeds the next hypothesis.
A good hypothesis names the change, the expected effect, and the reason. For example: "Lowering the first reward threshold from 5 to 3 referrals will raise the share of subscribers who make at least one referral from 4% to 5%, because the first reward feels reachable."
Choosing metrics
Pick one primary metric before you start. Add a few guardrail metrics that tell you whether the win is real or whether it hurt something else.
| Role | Example metric | Why it matters |
|---|---|---|
| Primary | Share of subscribers who send at least one referral that leads to a confirmed signup | Directly measures the loop you changed |
| Secondary | Confirmed referred signups per 1,000 sends | Tracks volume, not just participation |
| Guardrail | Unsubscribe rate and spam complaint rate in each group | Catches annoyed readers |
| Guardrail | 30-day open rate of referred subscribers | Catches low-quality signups |
| Guardrail | Reward cost per confirmed subscriber | Keeps the economics sound |
Count confirmed signups only, as in the earlier attribution chapter. A test that "wins" on raw form submissions can lose once you remove unconfirmed and fraudulent entries.
Assigning subscribers to groups
Assignment must be random, stable, and independent between experiments. Stable means the same subscriber always lands in the same group, even if they open the email five times. A common method hashes the subscriber id together with the experiment name.
import hashlib
def assign_group(subscriber_id: int, experiment: str, variant_share: float = 0.5) -> str:
"""Return 'variant' or 'control' deterministically for a subscriber."""
key = f"{experiment}:{subscriber_id}".encode()
bucket = int(hashlib.sha256(key).hexdigest()[:8], 16) / 0xFFFFFFFF
return "variant" if bucket < variant_share else "control"
counts = {"variant": 0, "control": 0}
for sid in range(1, 10001):
counts[assign_group(sid, "first-reward-threshold-3")] += 1
print(counts) # roughly 5,000 in each groupIncluding the experiment name in the hash means a subscriber who is in the variant for one test is not automatically in the variant for the next. Without it, your experiments would share the same split and their effects would mix.
Store the assignment, or recompute it from the same function, so you can join groups to outcomes later.
Deciding how many subscribers you need
Small tests produce wins that vanish on repeat. Before launching, estimate how many subscribers each group needs to detect the effect you care about. Three inputs set the answer:
- The baseline rate of your primary metric, for example 4%.
- The smallest improvement worth acting on, for example 1 percentage point (4% to 5%).
- How much risk of error you accept. The usual choices are a 5% false-positive rate (significance level) and 80% power, meaning an 80% chance of detecting a real effect of that size.
from statistics import NormalDist
def sample_size_per_group(p_control: float, p_variant: float,
alpha: float = 0.05, power: float = 0.80) -> int:
"""Approximate subscribers needed in each group for a two-sided test."""
z_alpha = NormalDist().inv_cdf(1 - alpha / 2)
z_beta = NormalDist().inv_cdf(power)
variance = p_control * (1 - p_control) + p_variant * (1 - p_variant)
n = (z_alpha + z_beta) ** 2 * variance / (p_control - p_variant) ** 2
return int(n) + 1
print(sample_size_per_group(0.04, 0.05)) # about 6,700 per groupThat is about 13,400 subscribers for a one-point lift on a 4% baseline. If your list has 3,000 subscribers, you cannot detect a lift that small in a single test. Your options are to test a bigger change, run the test across several sends, or accept that you can only detect large effects.
Reading the result
When the planned sample has been collected, compare the two groups with a two-proportion z-test. It asks how often a gap this large would appear if the change did nothing.
from math import sqrt
from statistics import NormalDist
def two_proportion_test(success_a: int, n_a: int, success_b: int, n_b: int):
"""Return (difference, z, two-sided p-value) for variant B versus control A."""
p_a = success_a / n_a
p_b = success_b / n_b
pooled = (success_a + success_b) / (n_a + n_b)
se = sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b))
z = (p_b - p_a) / se
p_value = 2 * (1 - NormalDist().cdf(abs(z)))
return p_b - p_a, z, p_value
diff, z, p = two_proportion_test(280, 7000, 350, 7000)
print(f"lift={diff:.3%} z={z:.2f} p={p:.4f}") # lift=1.000% z=2.85 p=0.0043A p-value of 0.004 means that if the change had no effect, a gap this large would appear in about 0.4% of experiments. It does not mean there is a 99.6% chance the variant is better, and it says nothing about whether the lift is worth the reward cost. Always report the size of the lift alongside the p-value, and check the guardrails before shipping.
Measuring quality, not only quantity
The most common mistake in referral testing is declaring victory on signups. A more generous reward can raise referrals while pulling in people who never open an email. Quality shows up weeks after the signup, so build it into the test.
Give every test a follow-up checkpoint, such as 30 days after the last signup in the test window. Then compare the groups on retention. This query reports the share of each group's referred subscribers who are still subscribed and opened at least one email. It assumes a table experiment_assignments with the group, and an opens table.
SELECT a.experiment_group,
COUNT(*) AS referred_subscribers,
AVG(CASE WHEN s.unsubscribed_at IS NULL THEN 1.0 ELSE 0.0 END) AS still_subscribed,
AVG(CASE WHEN o.subscriber_id IS NOT NULL THEN 1.0 ELSE 0.0 END) AS opened_any
FROM referrals AS r
JOIN subscribers AS s ON s.id = r.referred_id
JOIN experiment_assignments AS a
ON a.subscriber_id = r.referrer_id
AND a.experiment = 'first-reward-threshold-3'
LEFT JOIN (
SELECT DISTINCT subscriber_id FROM opens
) AS o ON o.subscriber_id = s.id
WHERE s.confirmed_at IS NOT NULL
GROUP BY a.experiment_group;Notice that the group is attached to the referrer, because the referrer is the person who saw your change. The referred subscriber inherits the group of the person who invited them.
If the variant produces more referrals but a lower opened_any, compute the cost of each engaged subscriber instead of each signup. Compare the groups on that figure.
Pitfalls specific to this kind of test
- Peeking. Checking results every morning and stopping when p drops below 0.05 inflates your false-positive rate well above 5%. Fix the sample size and end date in advance, and look only at the end. If you need early stopping, use a sequential testing method designed for it.
- Testing many things at once. If you compare ten metrics or ten variants, one will look significant by chance. Declare one primary metric. Treat the rest as exploratory and confirm any surprising result with a second test.
- Interference between groups. Referrals cross groups: a control subscriber may receive an invitation from a variant subscriber. This blurs the difference between groups, usually shrinking the measured effect. Assigning by subscriber is acceptable for small programs, but note the limitation when you report.
- Novelty effects. A new reward banner draws attention for a week and then fades. Run the test for at least one full cycle of your send schedule, usually two to four weeks, and compare early and late days.
- Seasonality and sends. Both groups must receive the same emails on the same days. Never run control one week and variant the next.
- Recommendation network tests. You often cannot randomly split a partner's audience. Alternate your blurb across equal time slots, or ask the partner to rotate versions, and compare conversion per impression. Treat these results as weaker evidence than a randomized split and repeat them.
Keeping a log and iterating
An experiment log keeps your program from forgetting what it learned. For each test, record:
- The hypothesis and the date range.
- The primary metric, the guardrails, and the planned sample size.
- The result: lift, p-value, and the 30-day quality numbers.
- The decision (ship, discard, retest) and the reason.
A modest lift that fails to repeat is common. Retesting a surprising win once before building on it costs little compared with rebuilding your program around noise. Over time the log shows which kinds of changes reliably help, such as lowering the first threshold, and which do not, so you can pick the next hypothesis from evidence.
The decision also feeds the k-factor from earlier chapters. After shipping a change that raises referral participation, re-measure invites per subscriber and invite conversion, recompute k, and update your growth projection. A change that lifts k from 0.20 to 0.25 shifts your five-cycle projection for 1,000 seed subscribers from about 1,250 to about 1,330. That figure comes from the chapter's formula, and it is a good sanity check on whether a test result matches the growth you see in practice.
Exercise
Your list has 20,000 subscribers. You want to test whether moving the share block to the top of the email raises the share of subscribers who send a referral that converts to a confirmed signup, from 3% to 4%. You split the list 50/50. After three days the variant is ahead with p = 0.03, and a colleague suggests shipping it now. What should you do, and why? Also name the quality check you should run later.
Show answer
Do not stop yet. First, compute the needed sample: for 3% versus 4% at 5% significance and 80% power you need roughly 5,300 subscribers per group, so 10,000 per group fits the list and the test should run to its planned end date. Stopping at the first p below 0.05 after peeking inflates the false-positive rate, and three days may also capture only a novelty effect. Let the test run its planned duration, then analyze once. Afterward, compare unsubscribe and spam complaint rates between groups, and at about 30 days compare the share of referred subscribers who are still subscribed and have opened at least one email, assigning each referred subscriber to the group of their referrer.