Browser SDK
The browser SDK is one script, https://app.erised.run/sdk/v0.js (under 5 KB gzipped), loaded by a two-line snippet. It uses a publishable key (pk_live_…), which is safe to expose.
The snippet
<script>
window.cdp = window.cdp || [];
window.cdp.push(['init', 'pk_live_YOUR_PUBLISHABLE_KEY']);
</script>
<script async src="https://app.erised.run/sdk/v0.js"></script>
Calls pushed before the script loads are queued and replayed in order. Once it has loaded, window.cdp is also a function: cdp('track', …) and window.cdp.push(['track', …]) do the same thing.
init options
cdp('init', key, options), once per page; a second init is ignored.
| Option | Default | Meaning |
|---|---|---|
endpoint |
the origin the script was loaded from | Where events are sent, e.g. '/erised' behind a first-party proxy. No trailing slash. |
consent |
false |
true when the site has cookie consent on: nothing is collected until the visitor grants analytics. See Consent. |
errors |
false |
true reports uncaught errors and unhandled promise rejections. See Error reporting. |
release |
— | Your build (e.g. a git SHA), attached to errors |
environment |
— | e.g. production, attached to errors |
Calls
| Call | What it does |
|---|---|
cdp('track', name, properties?) |
Records an action. name is required, snake_case (signup_started). |
cdp('page', properties?) |
Records a page view. Rarely needed: the SDK sends one on load and on every route change. |
cdp('identify', userId, traits?) or cdp('identify', { userId?, email?, traits? }) |
An unverified identify from the browser. It never merges two people and its userId is not attached; use the server identify for that. |
cdp('reset') |
At logout: forgets the user and starts a new anonymous id. |
cdp('captureError', error, { level?, tags?, fingerprint? }) |
Reports an error you caught. Works with or without errors: true. |
cdp('consent') |
Returns the visitor's consent choice, or null. |
cdp('onConsent', fn) |
Calls fn(choice) at load when a choice exists, and on every change. |
cdp('showConsent') |
Reopens the consent preferences (your "Cookie settings" link). |
cdp('grantConsent', categories?) / cdp('rejectConsent') / cdp('withdrawConsent') |
Record a choice from your own UI instead of the banner. |
Unknown calls are ignored: the SDK never throws into your page.
What each event carries
Every event gets an anonymousId, a messageId, a timestamp, and a context with the page (url, path, referrer, search, title), locale, timezone, userAgent and the library version. After an identify, the userId rides along too. Erised adds country, browser, OS, device class and UTM parameters on the server; the IP address is never stored.
Page views are named page_viewed and carry path and title in their properties.
The SDK never reads form fields and captures nothing automatically beyond page views, and uncaught errors when errors: true is set.
Storage
| Name | Where | Holds |
|---|---|---|
erised_anonymous_id |
cookie (first-party, host-only, SameSite=Lax, 1 year) and localStorage |
The visitor's anonymous id. Your server reads the cookie to identify. |
erised_user_id |
localStorage | The id from the last browser identify. |
erised_queue |
localStorage | Events not yet delivered. |
erised_session_id |
sessionStorage | The browser session. |
erised_consent |
cookie | The consent choice, when consent is on. |
With consent on, none of these except erised_consent exist until the visitor grants analytics, and withdrawing deletes them.
Delivery
- Events are sent to
POST /v1/batchevery 2 seconds, or as soon as 10 are waiting. - When the page is hidden or closed, the queue is sent with
sendBeacon. - Undelivered events wait in localStorage (at most 100, oldest dropped first) and survive a reload.
- A
429keeps the batch and retries after theRetry-Afterdelay; a5xxor a network error retries with backoff (1 to 30 seconds). Any other4xxdrops the batch, which could never succeed.
A first-party proxy
To load the script and send events from your own domain, proxy two paths. With Next.js:
// next.config.mjs
export default {
async rewrites() {
return [
{ source: '/erised/sdk.js', destination: 'https://app.erised.run/sdk/v0.js' },
{ source: '/erised/v1/:path*', destination: 'https://app.erised.run/v1/:path*' },
];
},
};
<script>
window.cdp = window.cdp || [];
window.cdp.push(['init', 'pk_live_YOUR_PUBLISHABLE_KEY', { endpoint: '/erised' }]);
</script>
<script async src="/erised/sdk.js"></script>