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

# SDK Configuration

> Full reference for all configuration options available when initializing AdXensor via the npm package.

Full reference for all configuration options available when initializing AdXensor via the npm package.

## `AdXensorConfig`

Pass these options to `AdXensor.getInstance(config)` or `new AdXensor(config)`:

| Option     | Type      | Required | Default                        | Description                                                                          |
| ---------- | --------- | -------- | ------------------------------ | ------------------------------------------------------------------------------------ |
| `siteId`   | `string`  | ✅        | —                              | Your Site ID from the publisher dashboard (`pub-XXXXXXXX`)                           |
| `apiKey`   | `string`  | —        | `undefined`                    | Optional publisher API key sent as `X-Publisher-Key` header                          |
| `apiUrl`   | `string`  | —        | `https://core.adxensor.com/v1` | Override the API base URL (useful for self-hosted or staging)                        |
| `lazyLoad` | `boolean` | —        | `true`                         | Fill slots only as they enter the viewport (IntersectionObserver with 200 px margin) |
| `debug`    | `boolean` | —        | `false`                        | Enables verbose console logging and exposes `window._adx`                            |

### Example

```typescript theme={null}
import { AdXensor } from '@adxensor/publisher-sdk';

const adx = AdXensor.getInstance({
  siteId:   'pub-XXXXXXXX',
  lazyLoad: true,
  debug:    process.env.NODE_ENV === 'development',
});

adx.init();
```

## `SlotOptions`

Options you can pass to `adx.fill()`, `adx.defineSlot()`, or `adx.push()`:

| Option   | Type                 | Default                 | Description                                  |
| -------- | -------------------- | ----------------------- | -------------------------------------------- |
| `slotId` | `string`             | Auto-detected           | Override the slot ID used for reporting      |
| `format` | `AdFormat \| 'auto'` | `'auto'`                | Ad size to request                           |
| `lazy`   | `boolean`            | Global `lazyLoad` value | Override lazy loading for this specific slot |

## CDN script attributes

When using the CDN snippet, pass options as data attributes on the `<script>` tag:

| Attribute        | Required | Default                        | Description                                       |
| ---------------- | -------- | ------------------------------ | ------------------------------------------------- |
| `data-ad-client` | ✅        | —                              | Your Site ID (`pub-XXXXXXXX`)                     |
| `data-api-key`   | —        | —                              | Optional API key                                  |
| `data-api-url`   | —        | `https://core.adxensor.com/v1` | Override API base URL                             |
| `data-lazy-load` | —        | `"true"`                       | Set to `"false"` to disable lazy loading globally |
| `data-debug`     | —        | —                              | Presence attribute — enables debug mode           |

```html theme={null}
<script async
  src="https://cdn.adxensor.com/tag.js"
  data-ad-client="pub-XXXXXXXX"
  data-lazy-load="true"
  data-debug>
</script>
```

## Singleton pattern

The SDK uses a singleton: multiple calls to `AdXensor.getInstance()` with the same config return the same instance. The first call creates it; subsequent calls reuse it.

```typescript theme={null}
// Both return the same instance
const adx1 = AdXensor.getInstance({ siteId: 'pub-XXXXXXXX' });
const adx2 = AdXensor.getInstance({ siteId: 'pub-XXXXXXXX' });
// adx1 === adx2 → true
```

## Resetting (SPA navigation)

To destroy the current instance and allow re-initialization (useful after client-side route changes):

```typescript theme={null}
AdXensor.reset(); // destroys the current singleton
```

Or just destroy without clearing the singleton reference:

```typescript theme={null}
adx.destroy(); // stops DOM observer and clears timers
```
