Skip to main content

Script tag attributes

The SDK reads these data-* attributes from its own <script> tag when it executes.
string
required
Your publishable key (cbh_pk_…). When present, the SDK initialises automatically. When absent, you must call init() yourself.
string
Override the API base URL. Defaults to https://sdk.cashbackhive.com/v1. Only needed for Cashback Hive-provided staging environments.
boolean attribute
Enable mock mode. The attribute’s presence enables it; the value is ignored.
boolean attribute
Log SDK activity to the console with a [CashbackHive] prefix. The attribute’s presence enables it.

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)

string
required
Your publishable key. Throws [CashbackHive] init requires a publishable key if missing.
string
default:"https://sdk.cashbackhive.com/v1"
API base URL. A trailing slash is stripped.
boolean
default:"false"
Enable mock mode.
boolean
default:"false"
Enable debug logging.
Returns the SDK instance, so calls can be chained.
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

string
The SDK version, e.g. "0.1.0".
boolean
true after init() has run (automatically or manually). Use this to check whether cbh:ready has already fired.
Promise<void>
Resolves once init() completes. Never rejects.
object
Offer catalogue methods. See Offers.
object
Signed-in member methods. See Member.
object
Sign-in and sign-out. See Auth.

Global hooks

CashbackHiveSdk
The SDK instance. Assigned as soon as sdk.js executes, before initialisation.
(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. In mock mode, beacons are logged (in debug mode) instead of sent.