Publishable keys
Every property has a publishable key that begins withcbh_pk_. You pass it to the SDK via the data-key attribute (or init({ key })), and the SDK sends it with every API request in the X-CBH-Key header.
Publishable keys are designed to be visible. Anyone can read them from your page source, and that’s fine, because the key alone can’t do anything harmful:
- It can only read offers for your property and act on behalf of a member who has explicitly signed in on your page.
- It is bound to your allowed origins (below). Requests from any other origin are rejected.
Allowed origins
Each property has a list of allowed origins — the schemes, hosts and ports the SDK is allowed to run on. An origin is thescheme://host[:port] part of a URL, for example:
Register every origin you’ll run on: production, staging, preview environments, and local development ports.
How enforcement works
The script file itself (sdk.js) is served to anyone, and window.CashbackHive will exist on any page that loads it. Origin enforcement happens at the API: the browser attaches an Origin header to each request, and the API checks it against the key’s allowed list.
On a non-allowed origin you’ll see:
cbh:readystill fires, andCashbackHive.initializedistrue.offers.list(),offers.get(),member.get()andmember.activity()reject with anSdkApiErrorwhosestatusis403.- The sign-in window will refuse to issue a token.
Multiple properties
If you run several sites, each with its own property and key, load the SDK with the key that belongs to that site. The SDK stores the member’s token under a key-specificlocalStorage entry (cbh:<key>:token), so sessions don’t leak between properties.
Rotating a key
If you need to rotate a publishable key, update thedata-key value in your deployed pages. Existing members will need to sign in again on the new key, because their stored token is scoped to the old one.