---
title: Quickstart
description: Add the snippet, identify people from your server, track conversions, reset at logout, and check that events arrive.
order: 2
---
# Quickstart

Most integrations take under an hour. You need an Erised site (sign in at [app.erised.run](https://app.erised.run/login)) and access to your product's pages and server.

## 1. Get your keys

- **Publishable key** (`pk_live_…`): on the site's **Install** screen. It goes in the browser.
- **Secret key** (`sk_live_…`): **Settings → API keys**, type *Secret*. It goes in your server's environment (for example `ERISED_SECRET_KEY`) and **never** in browser code or a public repository.

A key is shown once, when it is created. Erised stores only a hash.

## 2. Add the snippet to every page

Put this in the `<head>` of every page, or in your root layout:

```html
<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>
```

The snippet sends a page view on load and on every route change of a single-page app, so there is nothing to add for page views. Track the actions that matter:

```js
cdp('track', 'signup_started', { plan: 'growth' });
```

Calls made before the script loads are queued and sent once it does. If your site turned on cookie consent in Erised, add `{ consent: true }` as the third item of the `init` call: the snippet then shows the banner and collects nothing until the visitor agrees.

## 3. Identify people from your server

At **signup and at every login**, tell Erised who the browser belongs to. This is what joins the visitor's anonymous history to their account. Send it from your server with the secret key:

```js
// Node 18+ (fetch is built in). Runs after your own signup/login succeeds.
async function erisedIdentify(user, req) {
  try {
    await fetch('https://app.erised.run/v1/identify', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.ERISED_SECRET_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        userId: user.id,                                // your stable id, not the email
        anonymousId: req.cookies['erised_anonymous_id'], // set by the snippet; may be absent
        properties: {
          email: user.email,
          traits: { plan: user.plan },
        },
      }),
      signal: AbortSignal.timeout(3000),
    });
  } catch {
    // Never fail a signup or a login because analytics is unreachable.
  }
}
```

The snippet keeps the visitor's anonymous id in the `erised_anonymous_id` cookie. That cookie belongs to the page's own host. If your API runs on another host (`api.example.com` for a site on `example.com`), the cookie is not sent to it: read it in the browser and send it with the signup or login request instead:

```js
const match = document.cookie.match(/(?:^|; )erised_anonymous_id=([^;]*)/);
const anonymousId = match ? decodeURIComponent(match[1]) : undefined;
```

When the cookie is missing (consent not given, or no snippet on that page), send the call without `anonymousId`.

## 4. Track conversions from your server

Money and account changes come from the server, where they are true. Give each one a `messageId` built from your own record, so a retried request is stored once:

```js
await fetch('https://app.erised.run/v1/track', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ERISED_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    userId: user.id,
    event: 'order_paid',
    messageId: `order_paid:${order.id}`,
    properties: { amount: order.total, currency: 'USD' },
  }),
});
```

## 5. Reset at logout

In the browser, as part of your logout handler:

```js
cdp('reset');
```

This forgets the identified user and starts a new anonymous id, so the next person on the same device is never merged into the last.

## 6. Check that it works

Open your product, click around, sign up and log in. The **Install** screen ticks off the first page view, track event and identify as they arrive, and the **Live feed** shows every event as raw JSON within seconds.

A request Erised accepts is answered `202` with `{"received": n, "duplicates": n}`. A `401` (`unauthorized`) means a wrong or revoked key; a `429` means slow down (`rate_limited`, with a `Retry-After` header) or the plan's monthly limit is reached (`quota_exceeded`).
