> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kameleoon.API.Segments

> Reference for the Kameleoon.API.Segments methods that read, reevaluate, and trigger segments.

This module provides methods to manage segments and targeting.

## getAll

The `getAll()` method returns all live segments, including those associated with experiments, personalizations, or Audience tracking.

```javascript theme={null}
let segments = Kameleoon.API.Segments.getAll();
```

**Return value**

| Name | Type | Description |
| - | - | - |
| segments | Array | List of [Segment objects](https://docs.kameleoon.com/developer-docs/apis/activation-api-js/api-reference/objects/goal-segment-trigger-and-product.md#segment). |

## getById

The `getById()` method returns the segment for the specified ID.

```javascript theme={null}
let segment = Kameleoon.API.Segments.getById(123456);
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| id | Number | ID of the segment. This field is mandatory. |

**Return value**

| Name | Type | Description |
| - | - | - |
| segment | Object | [Segment object](https://docs.kameleoon.com/developer-docs/apis/activation-api-js/api-reference/objects/goal-segment-trigger-and-product.md#segment). |

## getByName

The `getByName()` method returns the segment for the specified name.

```javascript theme={null}
let segment = Kameleoon.API.Segments.getByName("My segment");
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| name | String | Name of the segment. This field is mandatory. |

**Return value**

| Name | Type | Description |
| - | - | - |
| segment | Object | [Segment object](https://docs.kameleoon.com/developer-docs/apis/activation-api-js/api-reference/objects/goal-segment-trigger-and-product.md#segment). |

## reevaluate

The `reevaluate()` method forces an immediate re-evaluation of the targeting conditions for the specified segment. Evaluation typically occurs at page load, resulting in statuses of **true**, **false**, or **undefined**. This method restarts the evaluation process as if the engine just initialized.

```javascript theme={null}
Kameleoon.API.Utils.addEventListener(document.body, "mouseleave", function (event) {
  if (event.clientY < 0) {
    Kameleoon.API.Segments.reevaluate(123456);
  }
});
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| id | Number | ID of the segment. This field is mandatory. |

## trigger

The `trigger()` method forces a segment trigger for the current visitor and bypasses targeting conditions.

```javascript theme={null}
Kameleoon.API.Segments.trigger(12345);
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| id | Number | ID of the segment. This field is mandatory. |
