# Active Variants API

If you wish to determine programmatically what variant Optibase has shown to the user, you can use the following global variable and function exposed by the Optibase Custom Script.

## window\.optibaseActiveVariants

Optibase Custom Script sets a global variable `window.optibaseActiveVariants` when all the tests have been loaded, and the variants have been chosen and displayed.

The variable is an array of active variants with a type of:

```typescript
type ActiveVariants = {
    userFriendlyTestId: string
    userFriendlyVariantId: string
}[]
```

The variable will only be set once the variants have been chosen and displayed. Before, the variable will be `undefined`.

*Note: Only Variants for Active and non-restricted Tests will be included. If the Main Variant is shown by default for a Test because the Test it is restricted or inactive, it will not be included in the* optibaseActiveVariants.

## window\.optibaseAddActiveVariantsListener

Optibase Custom Script sets a global function `window.optibaseAddActiveVariantsListener` that accepts a callback that will be triggered once the `window.optibaseActiveVariants` have been set.

The function is of type:

```typescript
type OptibaseAddActiveVariantsListener = (
  callback: (optibaseActiveVariants: ShownVariant[]) => void
) => void
```

You can use this to set a listener that will be triggered once the optibaseActiveVariants have been set.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optibase.io/integrations/custom-integrations/active-variants-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
