Skip to content

Different content for different people

The ebitex team
Part 16 of 20 of the series “Building Northwind Coffee”: a coffee cup, steaming, beside the part’s number.

Northwind sells to two kinds of people. Somebody buying a bag for their kitchen wants to know what it tastes like. A café buying by the sack wants to know about consistency, lead times and whether there will be more of it in March.

Both land on the same front page, and it currently addresses the first and ignores the second.

Again: nothing changed

Adding the second reading changed no Contract, no Template and no renderer.

statement.body has been personalizable since part 4, with an empty list of variants. This part adds the first variant. Same field, same Template, same renderer reading the same key.

That is part 15’s argument arriving on a different axis, and it lands for the same reason: the axis was declared when it was free.

The two axes do not know about each other

Northwind is now bilingual and personalized, which raises an obvious question: what does a French trade buyer get?

The trade variant’s French text. And nothing had to be built to make that true.

The value composes as personalization on the outside, locales within each arm:

{
  default: { default: "…", locales: { fr: "…" } },
  variants: [
    { conditions: [/* trade */], value: { default: "…", locales: { fr: "…" } } }
  ]
}

Pick the variant, then pick the language. Each modifier wraps a value and neither has an opinion about what is inside it, so N modifiers compose rather than needing N-squared combinations built. That is the same property that let enumerable and localizable compose back in part 4 — this is just the first time three of them are stacked at once.

The site sends a fact, the CMS decides what it means

This is the division worth understanding, because it is where personalization systems usually go wrong.

The site sends one property: buyerType. That is all it knows and all it claims.

What counts as a trade buyer is decided in the CMS. An Audience is a named rule over that context bag, and its definition is read live at delivery rather than frozen at publish — the same exception categories got in part 6, for the same reason. Widen who counts as a trade buyer and it takes effect on already-published pages, with nothing republished.

The division is: the application knows facts, the CMS owns meaning. Adding a new audience is not a deploy.

And it is worth being clear about what this is not. There is no tracking, no profile, no cookie following anybody around. It is a fact this page already has — sent with the request, used to resolve it, gone. Northwind gets it from ?buyer=trade, consumed out of the URL, which is exactly how a wholesale email would link somebody in.

One field, two answers. The trade variant is checked first; the default underneath is what everybody else reads.

The decision personalization forces on you

There is a genuine trade-off here and it is better to meet it deliberately than to discover it.

Send the context and the server resolves it. The response contains the winning text and nothing else. Simple to consume, and cache-hostile: the response varies by who asked, so it has to be cached by the full URL including the context, or not at all.

Send no context and resolve it yourself. The response carries the whole envelope — every variant and the rule that selects it — and the browser picks. One response serves every visitor, so it caches beautifully. The cost is that every variant’s content and its targeting rule are now in the browser, readable by anyone.

For Northwind’s "we also sell wholesale" that is completely fine, and the cacheability is worth having. For pricing that differs by segment, or anything you would not want a competitor to read, it is not.

Choose this per use case, not once for the whole site. The question is whether the variants you are not shown are a secret.

A React trap on the way through

One thing to get right in your own app code while wiring this up — nothing to do with the CMS, and no typecheck will catch it.

The obvious first move is to give useBuyerType a useState. Do that and every caller gets its own copy: the control in the footer and the page resolving the content each hold a separate one, so clicking the control moves the control and the words on the page do not change.

The fix is one shared store behind useSyncExternalStore. The lesson is the test that would have caught it: a test with one component on screen cannot see this bug. It needs two consumers of the same state and a click, which is a shape most component tests never take.

Anything read by two places at once is worth testing with two places at once.

Where this leaves us

A site that is bilingual, personalized, and built on a content model that has not changed since part 14.

Next: the front page carries a note about what is on the roaster this month, it is written in a hurry, and it is the one piece of copy here that should be read twice before it goes out.