Section-based personalization for AEM Edge Delivery Services (DA) pages: Section Metadata rows let rules (geo, device, visitor, URL/UTM param, page state, custom audiences), a decision engine (v1 API, OF1), an A/B split or Adobe Target (inline or popup) pick the EDS fragment a section shows, with the authored content as default. Consent first, measurement events per decision, a client runtime plus an optional Cloudflare edge worker, a simulator and Playwright checks.
88%
Does it follow best practices?
Impact
83%
0.83x1 of 3 eval scenarios. Add 2 more for a full score.
Low
Low-risk findings worth noting
rules, split and api sections before the HTML leaves the CDN, so the section is never
hidden in the browser. That makes it the right place for a personalized first section
(LCP).target sections always run in the browser.authoring-model.md).node scripts/install-edge.mjs <project> \
[--dir cdn/cloudflare-worker] [--name <worker>] [--origin main--<repo>--<owner>.aem.live] \
[--route www.example.com/*] [--account <cloudflare account id>] [--dry-run]It generates these files:
src/aem-worker.mjs: the official adobe/aem-cloudflare-prod-worker, vendored unchanged
(Apache-2.0, LICENSE_APACHE). Upgrade it by vendoring it again; never edit it.src/index.mjs: the wrapper that adds the decision route and post-processes HTML. It builds
fetchFragment(path, { signal }) on the official worker (<path>.plain.html, same host), so
fragments use the same origin, auth and cache settings as pages. One deadline
(fragmentTimeout, 1000 ms) covers the request and its body; on expiry the signal aborts it.src/personalization/:
personalize.js, html.js and adapters/of1.js (skill-owned);rules.js, section-spec.js, outcomes.js, contract.js, context.js, provider-api.js
and sources/split.js, copied unchanged from scripts/personalization/. Re-run install-edge
after updating them;edge-config.js (site-owned, never overwritten).wrangler.toml, from the template. name comes from the repo and ORIGIN_HOSTNAME from the
git remote; route and account_id stay commented out until given.The worker folder's top-level directory is added to .hlxignore, so EDS doesn't serve it.
Existing worker (--existing <dir>): only src/personalization/ is added, and the wrap
instructions are printed. Apply the wrap to the entry point and show the diff in the summary:
import config from './personalization/edge-config.js';
import { handleApiRoute, personalizeResponse } from './personalization/personalize.js';
// inside fetch(request, env, ctx); originFetch = the worker's own origin fetch
const fetchFragment = (path, { signal } = {}) => originFetch(new Request(new URL(`${path}.plain.html`, request.url), { signal }));
// before the origin fetch:
const routed = await handleApiRoute(request, env, config, { fetchPlain: fetchFragment });
if (routed) return routed;
// after the existing logic produced `response`:
return personalizeResponse(request, response, { config, env, cf: request.cf, ctx, fetchFragment });POST /pzn/decide (apiRoute) is the server route for browser engine requests
(decision-api.md). Point the browser's config.api.endpoint there and leave the browser
adapters empty, so the key never reaches the browser..plain.html) that contain personalized sections are
post-processed:
pzn-consent=1 cookie, or under an approved
exception in edge-config.js consent. Without either, every section is left to the
browser.cf.country and cf.regionCode; the cookies pzn-seen and pzn-vs (with
consent only), pzn-consent and pzn-split; the URL params; and the referrer host. Device,
state and audiences are unknown at the edge.api sections that the edge may decide. Sections it
would leave to the browser are not sent. The call has a 300 ms budget, and its answer is
cached under the shared key only with cacheable: true and ttl > 0
(decision-api.md § Caching).api sections: the engine's
answer, then the Rule rows, then the default. For split sections: the cookie, or a new
draw.Set-Cookie: pzn-split=…; Path=/; SameSite=Lax; Secure.<meta name="pzn-geo"> is injected when a rule uses geo, so the browser agrees
on the sections the edge left.Cache-Control: private, no-cache; ETag, Last-Modified and Content-Length
are removed (no validators, so a conditional request can't revalidate an older personalized
page against the origin);
x-pzn is edge or deferred.cf.botManagement.verifiedBot, or a user-agent match such as Lighthouse or PSI) get
the default, with no engine call and no split cookie.?pzn…), when edge-config.overrides allows them (the default is
never), and pages with AEM Experimentation page metadata, are left entirely to the browser.| Result | When | Marked as | The browser |
|---|---|---|---|
| Applied | Decided, and the HTML swapped (or kept, when the decision is the default) | data-pzn-where="edge" data-pzn-status="applied", plus <template data-pzn-default> holding the authored content when a variant is shown | Measures only; never decides it again |
| Selected | Decided, but the fragment couldn't be fetched here, for a section the browser may not decide | data-pzn-status="selected" | Loads and swaps the selected variant; doesn't decide again |
| Left | No consent cookie or exception; a target section; Rule rows that need device, state or audience; invalid rows; the engine timed out or failed with no matching rule; the fragment failed | Not marked | Decides it as in client mode |
Both marked kinds carry data-pzn-variant, -source, -outcome, -reason, -decision (<id>#1),
-cached (when the answer came from a cache) and -tracking (the engine's tracking, at most
1 KB). The browser sends pzn:decided and pzn:applied with where: "edge" and those values,
then seen and clicked as usual.
Sections the browser may not decide. For a slow engine (of1) on the first section, the
edge doesn't leave the section when it stops waiting. It applies the default with outcome
timeout, so the browser doesn't call the engine again.
Final for the page view. A marked section changes only when:
no-consent;?pzn= override is used;pzn-consent cookie still says yes), and no approved exception for the section's source allows the
decision. The browser doesn't honor it: applied goes back to the template's default and
selected keeps the default without loading the fragment, both with outcome no-consent, and
nothing is sent for the edge's decision. When consent is given later, the browser decides them.edge-config.js has these keys:
fragmentPrefixes;consent: { withoutConsent, policyRef }, copied from config.js;botsGetDefault;overrides (never in production);fragmentTimeout (1000);api: endpoint, engine, timeout (300), routeTimeout (2000), headers(env),
mapRequest, mapResponse;apiRoute (/pzn/decide).Keep fragmentPrefixes, consent and api.engine the same as in config.js. The wrangler.toml
[vars] PZN_API_ENDPOINT overrides api.endpoint. Secrets are set only with
wrangler secret put, by the site owner.
# The edge logic over any HTML, faking request.cf, the consent cookie and the UA:
node scripts/simulate.mjs https://main--<repo>--<owner>.aem.page/<page> --edge --consent --country IN
node scripts/simulate.mjs content/<page>.html --edge --repo <project> --consent --country US --region CA
node scripts/simulate.mjs content/<page>.html --edge --repo <project> # no consent: all left
node scripts/simulate.mjs https://main--<repo>--<owner>.aem.page/<page> --edge --ua Googlebot
# The real worker (the origin must be main--*--*.aem.live, so use https locally):
cd <project>/cdn/cloudflare-worker
npx wrangler dev --local-protocol https
curl -sk -D - -o /dev/null https://localhost:8787/
curl -sk -XPOST https://localhost:8787/pzn/decide -d '{}' # 503 until an engine is set, then 403 (no Origin)
npx wrangler deploy --dry-run --outdir /tmp/pzn-worker # bundle check, no uploadPages reach aem.live only after they are published, so before that rely on
simulate.mjs --edge. With --repo, the local content/ folder serves the fragments.
Expected results:
x-pzn: edge, with the right data-pzn-variant and data-pzn-status per section;<template data-pzn-default> on each applied variant;pzn-split only with consent or the exception;cache-control: private, no-cache.verify-preview.mjs --scenarios replays the pilot scenarios through this same edge code. Use
--perf --edge --uncached on the deployed site to measure it.
wrangler login always fails. Hand the user an interactive
login (in Claude Code, ! npx wrangler login), or have them set CLOUDFLARE_API_TOKEN (and
CLOUDFLARE_ACCOUNT_ID).route and account_id in wrangler.toml.npx wrangler secret put PZN_API_KEY # only with a decision engine
npx wrangler secret put ORIGIN_AUTHENTICATION # only for protected sites
npx wrangler deployX-Forwarded-Host.curl -A Googlebot..tessl-plugin
skills
personalize
assets
reference
scripts
test
fixtures
browser
contract
examples
decision-feedback
decision-request
decision-response
measurement-event
invalid
section
site-config
site
content
scripts
personalization