View as Markdown

Using an AI coding assistant

Erised is built to be integrated by an AI coding assistant working in your repository. Give it the prompt below; it reads these docs, makes the changes, and you check the result on the Install screen.

The Install screen in the app has the same prompt with your site's settings filled in, under Set up with an AI assistant, with a Copy button.

The prompt

Integrate Erised (customer data platform) into this codebase.

Read https://erised.run/llms.txt and the pages it links before writing code,
and follow the "Rules" section of https://erised.run/docs/ai-assistants.md exactly.

My settings:
- API origin: https://app.erised.run (the snippet loads https://app.erised.run/sdk/v0.js)
- Publishable key (browser): pk_live_YOUR_PUBLISHABLE_KEY
- Secret key (server): read it from the environment variable ERISED_SECRET_KEY.
  Never write the secret key in code, config files or the browser bundle.
- Cookie consent in Erised: off

Do this:
1. Add the browser snippet to every page (root layout or the shared <head>).
2. Track the 3–5 product actions that matter most, in the browser, with
   snake_case names. Propose the list before adding them.
3. On the server, after a successful signup and after every successful login,
   send a verified identify (POST /v1/identify) with the user's stable id,
   email and the erised_anonymous_id cookie.
4. On the server, track money and account changes (for example order_paid,
   subscription_started) with POST /v1/track and a deterministic messageId.
5. Call cdp('reset') in the browser when the user logs out.
   Then add error reporting: errors: true and release in the init call, and a
   server reportError helper (POST /v1/error) wired to the framework's error
   hook, as https://erised.run/docs/errors.md shows.
6. Add the "Erised rules" block from https://erised.run/docs/ai-assistants.md
   to this repository's AGENTS.md (or CLAUDE.md), creating the file if needed.
7. Tell me which files you changed and how to check the result on the
   Install screen of app.erised.run. If the "erised" MCP server is connected,
   check it yourself with get_install_status and check_identity.

Rules

An integration is correct only if it follows all of these.

  1. The secret key (sk_live_…) never reaches a browser. It lives in a server environment variable. Only the publishable key (pk_live_…) appears in page code.
  2. Identify from the server, at signup and at every login, with POST /v1/identify, the secret key, your stable userId (your database id, not the email), properties.email, and the anonymousId from the erised_anonymous_id cookie. A browser identify is unverified and never merges two people; it does not replace the server call.
  3. The erised_anonymous_id cookie belongs to the page's host. Read it on a server that shares that host, or read it in the browser (document.cookie) and send it with the login or signup request. If it is missing, send the identify without anonymousId; never invent one.
  4. Conversions come from the server with POST /v1/track and a messageId derived from your own record (for example order_paid:<order id>), so a retry is stored once.
  5. Call cdp('reset') on logout, in the browser.
  6. Event names are snake_case, object then past-tense verb: signup_completed, order_paid, invite_sent. One name per action across browser and server.
  7. No secrets or sensitive data in properties: no passwords, tokens, card numbers or free-text form fields. The email belongs in properties.email of an identify, nowhere else.
  8. Erised must never break your product. Server calls use a short timeout and swallow errors (log them); a failed analytics call never fails a signup, login or payment.
  9. Respect consent. If cookie consent is on for the site, pass { consent: true } in init and do not set the anonymous id cookie yourself.
  10. Do not add other trackers or forward Erised events to third parties.
  11. Error reporting is opt-in: errors: true with release (the build's git SHA or version) and environment in init; server errors go through one reportError helper with a short timeout. See Error reporting.
  12. An error report never carries request bodies, cookies or auth headers: the message, the stack, and at most the method, path and user agent.

The "Erised rules" block for your repository

Keep these lines in AGENTS.md or CLAUDE.md, so later changes made by an assistant keep the integration correct:

## Erised (analytics) rules
- Docs: https://erised.run/llms.txt. Follow https://erised.run/docs/ai-assistants.md#rules.
- ERISED_SECRET_KEY (sk_live_…) is server-only. Only the publishable key (pk_live_…) may appear in browser code.
- Server identify (POST https://app.erised.run/v1/identify) after every signup and login, with userId, properties.email and the erised_anonymous_id cookie when present.
- Server conversions (POST /v1/track) carry a deterministic messageId, e.g. order_paid:<order id>.
- cdp('reset') runs on logout.
- Event names: snake_case, object_past-tense-verb. No secrets, passwords or free text in properties.
- Analytics calls never block or fail a user action: short timeout, errors logged and ignored.
- Errors: errors: true + release in init; server errors via one reportError helper (POST /v1/error, secret key). Never bodies, cookies or auth headers.

Checking the result

After the assistant is done, open your product, sign up, log in and log out. On the Install screen of app.erised.run, the first page view, track event and identify tick off as they arrive; the Live feed shows each event's JSON.