Skip to content

[PREVIEW — DO NOT MERGE] Location matcher segmentation demo - #9

Closed
JonasJesus42 wants to merge 1 commit into
mainfrom
preview/location-matcher-demo
Closed

[PREVIEW — DO NOT MERGE] Location matcher segmentation demo#9
JonasJesus42 wants to merge 1 commit into
mainfrom
preview/location-matcher-demo

Conversation

@JonasJesus42

Copy link
Copy Markdown
Collaborator

Caution

DO NOT MERGE. This branch exists only to produce a Cloudflare Workers preview deploy so we can demo the regional segmentation flow end-to-end. Every commit here is intentionally throwaway code: temporary matcher override, demo home variant, QA route, dev region override. None of it is safe for main.

What this previews

The full Location matcher segmentation flow:

  1. Visitor in Rio opens / → Carousel renders 🌊 Olá, Rio de Janeiro! Frete grátis para todo o estado.
  2. Visitor in São Paulo opens / → Carousel renders 🏙️ E aí, São Paulo! Retire na loja do Morumbi hoje.
  3. Anywhere else → original "Skate into Adventure!!" carousel copy.

Cache keys are split via regionId in buildSegment (already on main from #8) so different regions get distinct cache entries.

QA tools on this preview

  • /geo-debug — diagnostic page with the resolved geo source + a matrix of 9 sample matcher rules (SP / RJ / "47" raw / country=Brasil / haversine SP / haversine Rio / empty entry / exclude) and a live RegionGreeting banner that swaps per region.
  • ?region=XX on any URL — dev override that rewrites cf-region-code on the inbound request. Lets QA / admins preview any region from a single IP. This is exactly why this branch can't go to main — anyone with the URL can bypass real geo.
Preview URL What you should see
/?region=SP orange São Paulo banner on home Carousel
/?region=RJ blue Rio de Janeiro banner
/?region=MG original "Skate into Adventure" (fallback)
/geo-debug matcher diagnostic with real geo
/geo-debug?simulate=SP matcher diagnostic + RegionGreeting banner switched to SP

Why this branch needs the local matcher override

@decocms/start@5.2.1 (pinned in this repo) ships a buggy built-in website/matchers/location.ts that drops Brazilian visitors entirely. The fix is in decocms/deco-start#209 but not yet released. Until then, src/matchers/location.ts here is a verbatim copy of the fixed matcher, registered via customMatchers so it overrides the framework's built-in.

When #209 merges and we bump @decocms/start, every file in this preview can be deleted.

Followups (not this PR)

  • Merge decocms/deco-start#209 → release @decocms/start@5.x.x
  • Bump @decocms/start on Bagaggio / Miess / Granado, drop any local override copies
  • Move the demo home variants into the actual merchant's decofile via admin.deco.cx UI (not by hand-editing JSON)

🤖 Generated with Claude Code

This branch exists ONLY to produce a Cloudflare Workers preview deploy
for demoing the regional segmentation flow to merchants and the team.
It is not safe to merge into main.

What this adds (all should be reverted before any merge):

* .deco/blocks/pages-home.json — Carousel section [2] wrapped in a
  website/flags/multivariate/section.ts flag with three Location-matcher
  variants: regionCode=RJ → "Olá, Rio de Janeiro!", regionCode=SP →
  "E aí, São Paulo!", fallback (always.ts) → original "Skate into
  Adventure!!" copy. Mimics exactly what admin.deco.cx writes when a
  merchant adds a region variant through the UI.
* src/server/cms/blocks.gen.json — regenerated to pick up the variant.
* src/matchers/location.ts — local copy of the fixed matcher from
  decocms/blocks#209 (deco-cx/apps parity + cubic review fixes).
  Necessary because the framework version pinned here ships a buggy
  built-in. Delete once we bump to the release with #209.
* src/setup.ts — calls registerLocationMatcher() AFTER createSiteSetup
  so it overrides the buggy built-in (registerBuiltinMatchers runs
  inside createSiteSetup and would otherwise clobber it).
* src/routes/geo-debug.tsx — /geo-debug QA route. Resolves geo source,
  evaluates 9 sample matcher rules, and renders a RegionGreeting banner
  that flips per region. Comes with ?simulate=SP|RJ|MG|SC|47 shortcuts
  for testing without a real CF visitor.
* src/worker-entry.ts — adds a ?region= URL override wrapped around
  decoWorker. Lets QA preview any region from a single IP. Guarded by
  PREVIEW_REGION_OVERRIDE constant for clarity (still trivially
  bypassable — must NOT ship to production).

Preview URLs once GH Actions deploys:
  https://pr-<N>-storefront-tanstack-template.deco-cx.workers.dev/
  https://pr-<N>-storefront-tanstack-template.deco-cx.workers.dev/?region=SP
  https://pr-<N>-storefront-tanstack-template.deco-cx.workers.dev/?region=RJ
  https://pr-<N>-storefront-tanstack-template.deco-cx.workers.dev/geo-debug

Refs decocms/blocks#209
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant