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

# Segments

> Contextualize the chatbot based on pages

Segments allow you to adapt the chatbot's responses based on the page context.

## Concept

A **segment** is a specific context. For example:

* Home page → segment `landing`
* Pricing page → segment `pricing`
* Support page → segment `support`

The chatbot only uses the corpus associated with the active segment.

## Usage

### Via HTML

```html theme={null}
<!-- Home page -->
<script
  src="https://animam.ai/widget.js"
  data-tenant="your-slug"
  data-segment="landing"
></script>

<!-- Pricing page -->
<script
  src="https://animam.ai/widget.js"
  data-tenant="your-slug"
  data-segment="pricing"
></script>
```

### Via JavaScript

```javascript theme={null}
// Change segment dynamically
window.Animam.setSegment("checkout")
```

Useful for SPAs (Single Page Applications) where the segment changes without page reload.

## Dashboard configuration

1. Go to **Dashboard > Knowledge Base**
2. For each entry, assign one or more segments
3. Entries without a segment are available everywhere

## Concrete example

### E-commerce scenario

| Segment    | Corpus                 | Example question              |
| ---------- | ---------------------- | ----------------------------- |
| `landing`  | Product presentation   | "What is your product?"       |
| `pricing`  | Pricing, subscriptions | "What's the price?"           |
| `checkout` | Payment, shipping      | "What payment methods?"       |
| `support`  | Technical FAQ          | "How do I reset my password?" |

### Implementation

```html theme={null}
<!-- pages/index.html -->
<script src="https://animam.ai/widget.js" data-tenant="shop" data-segment="landing"></script>

<!-- pages/pricing.html -->
<script src="https://animam.ai/widget.js" data-tenant="shop" data-segment="pricing"></script>

<!-- pages/checkout.html -->
<script src="https://animam.ai/widget.js" data-tenant="shop" data-segment="checkout"></script>
```

## Default segment

If no segment is specified, the chatbot uses:

1. Entries from the `default` segment
2. Entries without an assigned segment

## Best practices

<Tip>
  Create a `global` segment for general questions (hours, contact, about) available on all pages.
</Tip>

* Limit the number of segments (5-10 max)
* Name them clearly (`pricing` not `seg_01`)
* Test each segment individually
