# tys.experiment()

> The visitor's A/B holdout assignment when the store runs one (null otherwise).

Source: https://docs.tryyoursize.com/reference/web/client-experiment/

*Method* · `@tryyoursize/sdk`

The visitor's A/B holdout assignment when the store runs one (null otherwise). Save `visitorId` with the order (POST /v1/orders `visitor_id`) so returns are attributed to the right arm.

```ts
experiment(): Promise<ExperimentAssignment | null>;
```

## Returns

`Promise<ExperimentAssignment | null>`: The assignment, or `null` when the store runs no A/B holdout (or the API cannot be reached: then everyone sees TryYourSize).

- **`experimentId`** (`string`, required)
- **`arm`** (`ExperimentArm`, required)
- **`visitorId`** (`string`, required): The anonymous visitor ID: save it with the order (`visitor_id` in POST /v1/orders).

## Example

**JavaScript**

```js
const a = await tys.experiment();
// Keep it with the cart; your server sends it with the order.
if (a) cart.attributes.tys_visitor_id = a.visitorId;
```

**Node.js**

```ts
await tys.orders.create({
  id: "order_1042",
  visitor_id: cart.attributes.tys_visitor_id, // from tys.experiment() in the browser
  // …lines, currency
});
```

## See also

- [A/B holdout](https://docs.tryyoursize.com/guides/ab-holdout.md)
- [Orders and returns](https://docs.tryyoursize.com/guides/outcomes.md)
