docs: document Sidekick Experimentation panel setup for v2#61
docs: document Sidekick Experimentation panel setup for v2#61keepthebyte wants to merge 1 commit into
Conversation
v2 replaced the plugin's own in-page overlay with a hosted MFE panel
that the AEM Sidekick browser extension loads on demand, but nothing
in the README or experiments.md documented how to actually enable it
in a project. This adds:
- A new "Enabling the Sidekick Experimentation panel" section in the
README covering the three required pieces: registering the plugin
in tools/sidekick/config.json, adding the page-side listener script
that responds to the toolbar click, and loading that script from
head.html (easy to miss since it's the one piece nothing else wires
up automatically).
- A callout for projects already migrated to the unified ("helix5")
config format (e.g. via Experience Workspace), where Sidekick reads
plugins from the persisted admin config rather than a live read of
tools/sidekick/config.json off the code bus, and where the admin
config API's PUT/POST verbs are inverted from typical REST
conventions (PUT creates-only, POST updates).
- documentation/sidekick/config.json and
documentation/sidekick/aem-experimentation.js as copy-pasteable
reference files matching what's inlined in the README.
- A correction to documentation/experiments.md's Simulation section,
which still described the v1 in-page overlay as automatic and
referenced the wrong query parameter name (audience instead of
experiment).
All of this was worked out first-hand instrumenting a real project
against the v2 branch, including the config propagation and PUT/POST
gotchas, which cost real debugging time without any of this being
documented anywhere.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks for this @keepthebyte — the reference implementation and the write-up of the helix5 / PUT-vs-POST gotchas were exactly what was needed to pin down the problem. We opted to fix this in the plugin itself rather than as project-side docs: #62 moves the listener/MFE-loading logic into the plugin's Given that, I'd suggest we close this one in favor of #62 once it lands, but I've kept your |
## Summary In v2 the experiment/audience/campaign simulation UI was moved out of the plugin's own injected overlay and into a hosted MFE that the [AEM Sidekick extension](https://chromewebstore.google.com/detail/aem-sidekick/igkmdomcgoebiipaifhmpfjhbjccggml) opens. But nothing on the page ever loaded it: `loadLazy()` in `src/index.js` was an empty placeholder, so the Sidekick "Experimentation" button dispatched its custom event to nobody — a silent no-op with no console error. This is the issue reported in [SITES-48456](https://jira.corp.adobe.com/browse/SITES-48456). This makes the plugin own that wiring in its lazy phase, so a consuming project no longer copies a listener script into `tools/sidekick/` or adds anything to `head.html`. ## Changes - **`loadLazy(document, options)`** now: - binds the Sidekick toolbar button (`custom:aem-experimentation-sidekick`) to the panel, falling back to the `sidekick-ready` event since the extension injects its element asynchronously; - lazy-loads the hosted MFE `client.js` on first use and toggles the panel thereafter; - opens the panel automatically on a `?experiment=<id>/<variant>` simulation deep-link; - restores the panel after a variant-switch triggers a full-page reload. - It is gated to preview/dev only (`setDebugMode`) and **never runs in production**. - **New `simulationUI` option** — `'auto'` (default) | `'sidekick'` | `'universal-editor'` | `false` — provides a clean way to distinguish the **EDS + Sidekick** surface from the **Universal Editor**, where the panel is delivered as a UE extension instead. `'auto'` only activates on the Sidekick path, so a UE context naturally gets nothing. - `setupCommunicationLayer` is now **idempotent**, so the eager and lazy phases can both ensure the `postMessage` handshake exists (the panel now works even on preview pages with no experiment configured yet). Its reload handler also preserves the panel's open state across the reload. - **Docs**: README gains `runExperimentationLazy` in the loader, the `loadLazy()` wiring, the `simulationUI` option, and an **"Enabling the simulation panel (AEM Sidekick)"** section. That section keeps the still-necessary Sidekick plugin registration (`config.json`) and the helix5 persisted-config / PUT-vs-POST gotcha, and drops the obsolete copy-script / `head.html` steps. `documentation/experiments.md`'s Simulation section is corrected (v1 overlay → v2 panel, `audience` → `experiment` query param). Adds `documentation/sidekick/config.json` as a reference. ## Relationship to #61 This supersedes the fragile half of #61: the ~167-line copy-paste `aem-experimentation.js` listener is no longer needed because the plugin owns it (versioned, no CSP-nonce trap, no silent no-op). The genuinely project-side parts of #61 — the Sidekick `config.json` registration and the helix5 admin-config gotcha — are preserved here in the README. Thanks to @keepthebyte for working out the reference implementation and documenting the gotchas first-hand. ## Test plan - [x] `npm run lint:js` clean - [x] `npx playwright test` — 88 passed - [ ] Maintainer verification of the live Sidekick panel behavior against a real v2 project (MFE URL / handshake). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Dereje Dilnesaw <dilnesaw@adobe.com>
Summary
v2 moved the experiment/audience/campaign simulation UI out of the plugin's own injected overlay and into a hosted MFE panel loaded by the AEM Sidekick browser extension, but I couldn't find any documentation describing how to actually wire that up in a project.
setupCommunicationLayerinsrc/index.jsimplements thepostMessagehandshake side of it, but a consuming project still needs to register a Sidekick plugin and load a page-side listener script for the toolbar button to do anything.I worked this out first-hand while instrumenting a real (non-Xwalk) project against
v2, including two non-obvious gotchas that cost real debugging time:tools/sidekick/config.jsonoff the code bus — so just committing that file isn't enough.PUT/POSTverbs inverted from typical REST conventions:PUTonly creates a config and fails withconfig already existsif one is already there;POSTis what updates it.Changes
README.mdcovering all three setup steps, plus the config-propagation and PUT/POST gotchas above.documentation/sidekick/config.jsonanddocumentation/sidekick/aem-experimentation.jsas copy-pasteable reference files matching what's inlined in the README.documentation/experiments.md's "Simulation" section, which still described the v1 in-page overlay as automatic, and referenced the wrong query parameter name (audienceinstead ofexperiment) for forcing a variant.Test plan
documentation/sidekick/config.jsonis valid JSON anddocumentation/sidekick/aem-experimentation.jshas valid JS syntax.config already exists/ PUT-vs-POST issue and confirmed the POST workaround, and confirmed the Sidekick button was a silent no-op until the listener script was actually loaded fromhead.html.Opening as a draft since I'm an external contributor working from a downstream project, not an AEM Engineering team member — happy to adjust scope, tone, or wording to match your preferred docs style.
🤖 Generated with Claude Code