# SDK benchmarking

> Current Froomle documentation · [View canonical page](https://docs.froomle.com/froomle-doc-main/v2/js_lib/benchmarking.html)

Use this guide to configure assignment or change what a list shows. For experiment design and measurement, see [A/B testing and benchmarking](https://docs.froomle.com/froomle-doc-main/v2/guide/topics/ab-testing-benchmarking.html).

<a id="BenchmarkingSdk"></a>

## Benchmarking and A/B Testing with the SDK

Start with the defaults. Froomle assigns the visitor to `customer` or `froomle`. Each list keeps its original content for `customer` and displays returned Froomle recommendations for `froomle`. You do not need to turn on benchmarking or configure these defaults.

<a id="BenchmarkPrerequisites"></a>

### Decide what you want to compare

Agree on group names and the test split with Froomle before sending traffic. Then make two independent decisions:

1.  **Who assigns the visitor?** Let Froomle assign the group, or register the group selected by your own experimentation system.
    
2.  **What does each group see on each list?** Choose which groups see Froomle recommendations. The other groups see your original content, if provided.
    

For a model-vs-model test, show Froomle content to all participating groups and have Froomle configure the model variants. For a test against editorial or other customer content, provide the original cards and their item identities. Control and treatment describe the experiences you are comparing; they are not SDK settings or fixed group names.

<a id="BenchmarkModes"></a>

### Assign the group once

| Assignment owner | What to configure | Normal requests and events |
| --- | --- | --- |
| Froomle | Leave `currentGroup` unset. The SDK learns the group from the first valid recommendation response. | The SDK does not send `user_group`, even after it learns the group. |
| Your experimentation system | Register the resolved group with `setCurrentGroup(…​)` or `configureBenchmark({ currentGroup })` before SDK initialization. | The SDK sends the explicit `user_group`, including when the group is named `froomle`. A normal recommendation response must return the same group. |

The group stays fixed for the current assignment lifecycle and applies across lists. It is not the model version returned by the service. An unknown group or a contradictory normal response does not produce a tracked recommendation placement. The SDK reports the failure instead of switching groups or guessing what to show.

<a id="BenchmarkConfig"></a>

### Configure the SDK, if needed

| Setting | Default | Script-tag equivalent |
| --- | --- | --- |
| `allowedGroups` | `['customer', 'froomle']` | `data-froomle-benchmark-allowed-groups` |
| `showFroomleContentFor` | `['froomle']` for lists without their own policy | `data-froomle-benchmark-show-froomle-for` |
| `currentGroup` | Unset, so Froomle assigns it | `data-froomle-benchmark-current-group` |

Configuration precedence is defaults, then the SDK script attributes, then `configureBenchmark(…​)`. A call to `configureBenchmark(…​)` replaces the script configuration; omitted options use the defaults. A bare `data-froomle-benchmark` or `configureBenchmark()` can explicitly declare the defaults but is not required. The `setCurrentGroup(…​)` setter registers assignment separately. If both the effective configuration and the setter supply a group, both values must resolve and agree.

> **IMPORTANT:**
> 
> Coordinate custom groups with Froomle
> 
> Before sending traffic, tell Froomle the exact group names and agree on who assigns visitors, the traffic split, and which lists should return recommendations for each group. Confirm that the Froomle backend is configured to match. The SDK’s `allowedGroups` only tells it which group names to accept; it does not create backend groups. `showFroomleContentFor` controls frontend rendering, not the backend response.

For example, if you agree on `editorial` and `personalized`, set both options before SDK initialization. Lists without an override keep original content for `editorial` and display returned Froomle recommendations for `personalized`. This example leaves assignment with Froomle by not setting `currentGroup`.

```ts
import { configureBenchmark } from '@froomle/frontend-sdk'

configureBenchmark({
  allowedGroups: ['editorial', 'personalized'],
  showFroomleContentFor: ['personalized'],
})
```

The equivalent attributes on the SDK script tag are:

```html
data-froomle-benchmark-allowed-groups='["editorial","personalized"]'
data-froomle-benchmark-show-froomle-for='["personalized"]'
```

For external assignment using the script-tag hook, register your listener **before** inserting the SDK script. If your experiment provider is asynchronous, pass its promise directly to the setter. The SDK waits for it instead of treating a pending group as missing:

```html
<script>
  window.addEventListener('froomle:before-init', ({ detail: { sdk } }) => {
    // The provider returns a group from the agreed allowlist.
    sdk.setCurrentGroup(window.experiments.getGroup('homepage-recommendations'))
  }, { once: true })
</script>
<script defer
  src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js"
  data-froomle-env="sample_env"
  data-froomle-page-visit="home">
</script>
```

For external assignment in a module integration, register the group in your browser bootstrap before calling `init()` for declarative DOM, mounting SDK React components, or making the first standalone recommendation operation. `proxyReco(…​)` registers work when called, not when you flush it. Do not wait until a response arrives or change the assignment for individual placements.

<a id="BenchmarkShapes"></a>

### Decide what a list shows

A list’s `showFroomleContentFor` replaces the default for that list; it does not add to it. Use a list of allowed group names, `[]` for none, or the standalone value `'*'` for all allowed groups. Slots using the same logical list must agree on its policy. The policy changes what the SDK selects; it does not change the group or get sent to the Recommendations API.

| Selected content | Returned items | Result |
| --- | --- | --- |
| Customer | Empty or populated | Keep original content. Ignore the returned items for rendering. |
| Froomle | Populated | Display the returned items. |
| Froomle | Empty | Display no recommendation. A successful empty result does not switch the list to original content. |

If the list is set to show Froomle recommendations and a successful response contains no items, the SDK shows no recommendations. If the initial request fails, the SDK leaves the original markup in place. Use [SDK diagnostics](https://docs.froomle.com/froomle-doc-main/v2/js_lib/diagnostics.html#BrowserRuntime) to tell the two cases apart.

<a id="BenchmarkDeclarative"></a>

### Declarative DOM: set a list policy and identify original cards

Set `data-froomle-reco-show-froomle-for` on a slot or on a wrapper around its slots. The nearest marked wrapper supplies the inherited policy; if you also declare it on a slot, the declarations must agree. Each slot still needs its `data-froomle-reco` list name. In this example `more_stories` uses the default split, and `editors_picks` shows returned items to every allowed group:

```html
<article data-froomle-reco="more_stories"
         data-froomle-id="article-123"
         data-froomle-item-type="article">
  <a href="/stories/local-news" data-froomle-param-href="uri">
    <span data-froomle-param-inner="title">Local news</span>
  </a>
</article>

<section data-froomle-reco-show-froomle-for="*">
  <article data-froomle-reco="editors_picks">
    <a data-froomle-param-href="uri">
      <span data-froomle-param-inner="title"></span>
    </a>
  </article>
</section>
```

For a named set, write `data-froomle-reco-show-froomle-for='["customer","froomle"]'`. The set-valued script attributes use the same syntax. A single group may be written without JSON; multiple groups may also be separated by `;`, not commas. Use `*` on its own, not as an entry in an array.

**Preferred:** Render the original CMS card inside its placement and identify it with `data-froomle-id` and `data-froomle-item-type`, as in `more_stories`. Use the item ID and type supplied to Froomle for that content.

**Selector fallback:** If the CMS already renders a stable ID on a descendant and you cannot put it on the slot, add these attributes to the SDK script:

```html
data-froomle-benchmark-control-id-selector="#more-stories [data-article-id]"
data-froomle-benchmark-control-id-attribute="data-article-id"
data-froomle-benchmark-control-item-type="article"
```

Here `#more-stories` wraps the slots, with exactly one matching identity per card. For module initialization, the equivalent is `setBenchmarkControlIdentity({ selector: '#more-stories [data-article-id]', idAttribute: 'data-article-id', itemType: 'article' })` before `init()`. Selectors supply missing identity; they do not choose a group or change a list policy. If the SDK cannot identify an original card unambiguously, it does not track it as a recommendation.

<a id="BenchmarkProgrammatic"></a>

### Programmatic rendering

Use `showFroomleContentFor` on the list entry to override its default. Read the resulting `experience` to decide what to show; an empty `items` array on its own does not indicate customer content. See [Programmatic list requests](https://docs.froomle.com/froomle-doc-main/v2/js_lib/programmatic.html#programmatic-lists) for a rendering example and [Programmatic slot requests](https://docs.froomle.com/froomle-doc-main/v2/js_lib/programmatic.html#programmatic-slots) for the equivalent slot outcomes.

<a id="BenchmarkReact"></a>

### React rendering

Use [`useRecoList(…​)`](https://docs.froomle.com/froomle-doc-main/v2/js_lib/react.html#react-reco-list) with `customerItems` for a block of original cards, or [`useRecoEntry(…​)`](https://docs.froomle.com/froomle-doc-main/v2/js_lib/react.html#react-reco-entry) with `customerItem` for one card. Supply each original card’s identity with `getId` and, when needed, `getItemType`. `mapRecommendationItem` and `showFroomleContentFor` are top-level options on the hook query. Render the selected entries through [`FroomleReco`](https://docs.froomle.com/froomle-doc-main/v2/js_lib/react.html#react-reco-tracking) for automatic attribution. Use [`useCreateReco(…​)`](https://docs.froomle.com/froomle-doc-main/v2/js_lib/react.html#react-reco-slot) if the slot only displays a returned Froomle item.

<a id="BenchmarkImplementationOrder"></a>

### Verify both experiences

1.  Check who assigned the group, then check what each list selected. A group can see original content on one list and returned Froomle content on another.
    
2.  With tracking consent, confirm impressions and clicks identify the item actually displayed, its list name, and the same recommendation request ID. The SDK tracks eligible DOM and React cards that it registers. If you render the result independently, send these events explicitly.
    
3.  Use [SDK diagnostics](https://docs.froomle.com/froomle-doc-main/v2/js_lib/diagnostics.html#BrowserRuntime) to check assignment, list policy, response errors, and original-card identity. A resolved policy is not proof that a card was displayed or that an event was delivered.
