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

# Configuration

> Cashback Hive SDK configuration reference: every script tag data attribute, the manual init() options, and the instance properties on window.CashbackHive.

## Script tag attributes

The SDK reads these `data-*` attributes from its own `<script>` tag when it executes.

**data-key** `string` *required*

Your publishable key (`cbh_pk_…`). When present, the SDK initialises automatically. When absent, you must call `init()` yourself.

**data-api** `string`

Override the API base URL. Defaults to `https://sdk.cashbackhive.com/v1`. Only needed for Cashback Hive-provided staging environments.

**data-mock** `boolean attribute`

Enable [mock mode](https://developer.cashbackhive.com/guides/local-development.md#option-2-mock-mode). The attribute's presence enables it; the value is ignored.

**data-debug** `boolean attribute`

Log SDK activity to the console with a `[CashbackHive]` prefix. The attribute's presence enables it.

```html theme={null}
<script
  src="https://sdk.cashbackhive.com/sdk.js"
  data-key="cbh_pk_your_publishable_key"
  data-debug
  async
></script>
```

## Manual initialisation

If you omit `data-key`, initialise the SDK yourself. This is useful when the key comes from a runtime config, or you need to register an `on("ready")` listener before initialisation.

### `CashbackHive.init(options)`

**options.key** `string` *required*

Your publishable key. Throws `[CashbackHive] init requires a publishable key` if missing.

**options.apiBase** `string` (default: [https://sdk.cashbackhive.com/v1](https://sdk.cashbackhive.com/v1))

API base URL. A trailing slash is stripped.

**options.mock** `boolean` (default: false)

Enable mock mode.

**options.debug** `boolean` (default: false)

Enable debug logging.

**Returns** the SDK instance, so calls can be chained.

```html theme={null}
<script src="https://sdk.cashbackhive.com/sdk.js" async></script>
<script>
  // sdk.js is async, so wait for it to exist
  function whenLoaded(cb) {
    if (window.CashbackHive) return cb(window.CashbackHive);
    setTimeout(() => whenLoaded(cb), 50);
  }

  whenLoaded((sdk) => {
    sdk.on("ready", ({ version }) => console.log("ready", version));
    sdk.init({ key: window.APP_CONFIG.cashbackHiveKey });
  });
</script>
```

> [!NOTE]
>
> `init()` runs once. Subsequent calls are ignored and, in debug mode, log `init() called twice; ignoring`. The `cbh:ready` event and `onCashbackHiveReady` callback fire after manual `init()` just as they do with auto-initialisation.

## Instance properties

**version** `string`

The SDK version, e.g. `"0.1.0"`.

**initialized** `boolean`

`true` after `init()` has run (automatically or manually). Use this to check whether `cbh:ready` has already fired.

**ready** `Promise\<void\>`

Resolves once `init()` completes. Never rejects.

**offers** `object`

Offer catalogue methods. See [Offers](https://developer.cashbackhive.com/reference/offers.md).

**member** `object`

Signed-in member methods. See [Member](https://developer.cashbackhive.com/reference/member.md).

**auth** `object`

Sign-in and sign-out. See [Auth](https://developer.cashbackhive.com/reference/auth.md).

## Global hooks

**window\.CashbackHive** `CashbackHiveSdk`

The SDK instance. Assigned as soon as `sdk.js` executes, before initialisation.

**window\.onCashbackHiveReady** `(sdk) =\> void`

Optional callback you define. Called with the SDK instance after initialisation, immediately after the `cbh:ready` event is dispatched.

## Analytics beacons

The SDK sends lightweight analytics events to `POST /v1/events` so Cashback Hive can report on integration health. They're fire-and-forget (`keepalive: true`, errors swallowed) and contain no personal data beyond what's listed.

| Event | When | Payload |
| - | - | - |
| `sdk_loaded` | During `init()` | `url` (current page), `referrer`, `version` |
| `offer_click` | On `openOffer()` | `slug`, `subId` |

In mock mode, beacons are logged (in debug mode) instead of sent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.