Sub topic 11
Testing and iterating
This chapter assumes you can read basic Python and SQL. It also assumes you know how newsletter lists, open rates, and unsubscribes work. You have already seen the k-factor and quality-by-source metrics. Here you will use them to test growth tactics without fooling yourself.
Why test growth tactics
A referral reward, a new recommendation placement, or a rewritten invite can all feel like improvements. Subscriber counts also move for reasons unrelated to your change: a viral post, a holiday, a partner's send schedule. If you compare this week to last week, you can't separate your change from that noise.
A controlled test fixes this. You split readers into groups at the same time. One group sees the current version (the control). Another sees the change (the variant). Because both groups share the same calendar, only the change differs.
Pick one change and one metric
Change one thing per test. If you alter the reward and the invite wording together, you won't know which one worked.
Choose a primary metric before you start. For growth tests, avoid raw signups alone. Use a metric tied to quality, such as the share of new subscribers who confirm their address and are still subscribed after 30 days.
Also pick guardrail metrics. These are numbers that must not get worse. Good guardrails are unsubscribe rate, spam complaints, and open rate among new subscribers.
Assign groups consistently
Each reader must always land in the same group. Hash the subscriber id with a test name so assignment is stable and needs no stored table.
import hashlib
def assign_group(subscriber_id: int, test_name: str, variant_share: float = 0.5) -> str:
key = f"{test_name}:{subscriber_id}".encode()
bucket = int(hashlib.sha256(key).hexdigest(), 16) % 10000
return "variant" if bucket < variant_share * 10000 else "control"
for sid in (1, 2, 3, 42):
print(sid, assign_group(sid, "invite-copy-v2"))Including the test name means a reader can be in the control for one test and the variant for another. Without it, the same readers would always get every new variant.
Decide whether a difference is real
Suppose 4,000 readers saw each version of an invite. Control produced 120 confirmed referred signups. The variant produced 150. Is the gap real or chance?
A two-proportion z-test answers this.
from math import sqrt, erf
def two_proportion_test(x1, n1, x2, n2):
p1, p2 = x1 / n1, x2 / n2
pooled = (x1 + x2) / (n1 + n2)
se = sqrt(pooled * (1 - pooled) * (1 / n1 + 1 / n2))
z = (p2 - p1) / se
p_value = 2 * (1 - 0.5 * (1 + erf(abs(z) / sqrt(2))))
return p2 - p1, p_value
lift, p = two_proportion_test(120, 4000, 150, 4000)
print(f"lift={lift:.4f}, p={p:.3f}")This prints a lift of 0.0075 (0.75 percentage points) and a p-value of about 0.04. A p-value is the probability of seeing a gap this large if the two versions were actually identical. Below 0.05 is the usual threshold, so this result is borderline but significant.
Common errors
- Stopping early. Checking results daily and stopping when the p-value dips below 0.05 inflates false positives. Decide the sample size or duration in advance and wait.
- Too small a sample. Newsletters with a few thousand readers can only detect large effects. If you can't reach a useful sample, test bigger changes or run the test longer.
- Judging on signups only. A reward that doubles signups but halves 30-day retention is a loss. Check the quality query by source for each group.
- Overlapping tests. Two tests that touch the same readers can interact. Run one test per surface at a time.
- Ignoring seasonality. Run the test for whole weeks so weekday patterns affect both groups equally.
Compare quality by group
Add the test group to your attribution records, then compare retention.
SELECT t.test_group,
COUNT(*) AS signups,
AVG(CASE WHEN s.confirmed_at IS NOT NULL THEN 1.0 ELSE 0 END) AS confirm_rate,
AVG(CASE WHEN s.unsubscribed_at IS NULL THEN 1.0 ELSE 0 END) AS still_subscribed
FROM referrals AS r
JOIN subscribers AS s ON s.id = r.referred_id
JOIN test_assignments AS t ON t.subscriber_id = r.referrer_id
WHERE t.test_name = 'invite-copy-v2'
GROUP BY t.test_group;Note that the group is the referrer's group, because the referrer saw the invite. Referred readers are measured as outcomes of that group.
The iteration loop
Each test feeds the next. Record what you changed, the result, and what you learned. Ship winners, drop losers, and use the surprises to form the next hypothesis.
Exercise
A new reward raises referred signups by 40%, but 30-day retention of those signups drops from 70% to 40%. Control had 100 signups and the variant 140. Which group yields more retained subscribers, and what should you conclude?
Show answer
Control retains 100 × 0.70 = 70 subscribers. The variant retains 140 × 0.40 = 56. The control keeps more, so the reward attracts lower-quality signups and should not ship as is. Test a smaller or milestone-based reward, and use retained subscribers as the primary metric.
Exercise
Why do you hash the test name together with the subscriber id when assigning groups?
Show answer
It keeps each reader's group stable within a test while making assignments independent across tests. Without the test name, the same readers would land in the variant of every test.