Sub topic 10
Combining behaviour, interest, and lifecycle
This chapter assumes you know the three single-dimension segments from the earlier chapters. It also assumes you can read basic SQL and boolean logic (AND, OR, NOT). Here you will combine behaviour, interest, and lifecycle rules into narrower segments. You will also learn how to keep those segments large enough to use.
Why combine dimensions
Each dimension answers a different question:
- Behaviour: what has this person done recently?
- Interest: what topic do they care about?
- Lifecycle: where are they in their relationship with you?
A single dimension gives you a broad group. Two or three together give you a group that can receive a message written for all of them. "Active customers interested in running" can hear about a new running shoe. A lapsed customer who clicked running content can hear a win-back offer for the same topic.
Combining with AND, OR, and NOT
Most combined segments use AND between dimensions and OR inside one dimension.
| Rule | Meaning |
|---|---|
| lifecycle = active_customer AND interest = running | Must match both. The segment is narrower. |
| interest = running OR interest = cycling | Matches either. The segment is wider. |
| lifecycle = prospect AND NOT clicked in 30 days | Excludes a behaviour. |
Every AND shrinks the segment. Every OR grows it. When a combined segment is too small, loosen one dimension rather than dropping all of them.
Build from reusable pieces
Write each dimension as its own rule, then join them. This keeps each rule testable on its own. In SQL, a common table expression (CTE) is a named subquery you define with WITH. It is a good way to do this.
The lifecycle rule uses CASE. A CASE expression checks its branches in order and returns the first match. Each subscriber therefore gets exactly one stage, and the stages cannot overlap.
-- PostgreSQL: active customers interested in running
WITH staged AS (
SELECT id,
CASE
WHEN last_purchase_at >= now() - interval '90 days' THEN 'active_customer'
WHEN last_purchase_at IS NOT NULL THEN 'lapsed_customer'
WHEN created_at >= now() - interval '14 days' THEN 'new_subscriber'
ELSE 'prospect'
END AS lifecycle_stage
FROM subscribers
WHERE status = 'subscribed'
),
running_interest AS (
SELECT subscriber_id
FROM events
WHERE event_type = 'email_click'
AND topic = 'running'
AND occurred_at >= now() - interval '60 days'
GROUP BY subscriber_id
HAVING COUNT(*) >= 2
)
SELECT st.id
FROM staged st
JOIN running_interest ri ON ri.subscriber_id = st.id
WHERE st.lifecycle_stage = 'active_customer';Three things in this query matter:
stagedfilters onstatus = 'subscribed'. Because the join only keeps rows found instaged, unsubscribed contacts can never enter the result, even if they have running clicks.running_interestuses a count threshold (HAVING COUNT(*) >= 2) and a 60-day window. One click is weak evidence. Repeated clicks inside a window are stronger.- The final
JOINacts as AND. Switching to aUNIONof two such queries would act as OR.
Seeing the structure
The diagram shows how the three rules feed one combined segment.
Check the size before you send
A combined segment can be correct and still useless. Count it before you build a campaign.
-- PostgreSQL: size of each piece and of the combination
WITH staged AS (
SELECT id,
CASE
WHEN last_purchase_at >= now() - interval '90 days' THEN 'active_customer'
WHEN last_purchase_at IS NOT NULL THEN 'lapsed_customer'
WHEN created_at >= now() - interval '14 days' THEN 'new_subscriber'
ELSE 'prospect'
END AS lifecycle_stage
FROM subscribers
WHERE status = 'subscribed'
),
running_interest AS (
SELECT subscriber_id
FROM events
WHERE event_type = 'email_click'
AND topic = 'running'
AND occurred_at >= now() - interval '60 days'
GROUP BY subscriber_id
HAVING COUNT(*) >= 2
)
SELECT
(SELECT COUNT(*) FROM staged WHERE lifecycle_stage = 'active_customer') AS active_customers,
(SELECT COUNT(*) FROM running_interest) AS running_interested,
(SELECT COUNT(*)
FROM staged st
JOIN running_interest ri ON ri.subscriber_id = st.id
WHERE st.lifecycle_stage = 'active_customer') AS combined;Compare combined to the two inputs. If it is a small fraction of both, the segment may be too narrow. Your provider's minimum size for reliable testing is a useful floor.
Common errors
- Stacking too many rules. Three dimensions with tight thresholds can leave only a handful of people. Widen a window or lower a count.
- Mixing up OR and AND across dimensions. "Active customer OR interested in running" is a very wide group, not the narrow one you wanted.
- Overlapping lifecycle stages. If you write stages as separate queries instead of one ordered
CASE, a person can appear in two stages and get two messages. - Ignoring consent. Apply the subscription check first, as the
stagedrule does.
Exercise
A combined segment, "lapsed customers interested in running", contains only 12 people. Name two ways to enlarge it without removing a whole dimension.
Show answer
Widen the interest window (for example from 60 to 90 days) or lower the click threshold (from 2 clicks to 1). You could also add a related topic with OR, such as cycling, inside the interest dimension. Each change keeps all three dimensions in place.
Exercise
Why does the lifecycle rule use a single ordered CASE expression instead of four separate queries?
Show answer
CASE returns the first matching branch, so each subscriber gets exactly one stage. Separate queries could place the same person in two stages, such as a recent subscriber who also bought something, and they would receive overlapping messages.