adobe / adobe/aem-experimentation

resolveAudiences: batched, context-aware audience resolution

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
16
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Part of #66

## Problem

Each audience is resolved independently via an argument-less `options.audiences[key]()`, run in `Promise.all`. A remote decision engine wants **one** call per page with a shared context, then answers all audiences from that single response. Today integrators hand-roll a memoized fetch to avoid N round-trips.

## Proposal

An optional config hook that resolves many audiences at once with a shared context:

```js
loadEager(document, {
resolveAudiences: async (names, context) => {
// context: { visitorId, url, consent, geo, … }
// return e.g. { [name]: boolean } for the requested names
},
});
```

Plus ship a small **client helper** in the plugin that covers the common case — a memoized remote resolver with a timeout → control fallback — so integrators don't re-implement it each time.

## Acceptance criteria

- [ ] `resolveAudiences` is honored when provided; the per-audience `audiences[key]()` path is unchanged when it isn't (no-op default).
- [ ] Called once per scope with the full set of requested names and a documented `context` shape.
- [ ] Timeout / rejection falls back to control (unresolved) rather than blocking render indefinitely.
- [ ] Bundled memoized helper, with tests.

Contributor guide

Open the contributing guide

Research direction

Start at the loadEager entry point and trace the current per-audience options.audiences[key]() resolution and its Promise.all scope. Define the hook's requested-name and context behavior, then add tests covering the unchanged fallback path, one call per scope, timeout or rejection fallback, and the memoized helper; done means all acceptance criteria pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.