Paste this prompt into Claude, Codex, or your preferred coding agent. It tells the agent how to add Userbook, identify users, and track the standard SaaS lifecycle events.
Open https://userbook.io/docs/install and install Userbook in this app.
Use the Node SDK where server-side code is available:
- Install @userbook/node.
- Read the API key from USERBOOK_API_KEY.
- Create one shared Userbook client.
- Do not expose USERBOOK_API_KEY in browser/client bundles.
- Set USERBOOK_DEV_MODE=true only for local validation when outbound writes should be suppressed.
Identify users with userbook.identify() whenever a user signs up, signs in, changes profile/account details, changes plan, or completes onboarding.
Attach these fields when they are available:
- id: stable user id
- email
- name
- role
- organisation: { id, name } using the account/org/workspace id and name
- plan: { name, interval, cost, currency, trial_days, subscribed_at }
- signup_source
Track these standard lifecycle events with userbook.event():
- signed_up
- signed_in
- signed_out
- started_trial
- completed_onboarding
- activated
- upgraded
- downgraded
- changed_plan
- cancelled
- reactivated
- opened_email
- error
- custom
- closed_account
For every event, include identity_id with the same stable user id used in identify().
Do not duplicate organisation or plan details in event metadata when those details are already attached through identify().
Add useful event-specific description and metadata when available, such as source, route, feature, step, error_name, and error_message.
For revenue-impacting events, include cost and currency on the event itself so Userbook can connect product activity to customer value.
For application-specific behavior, send type: 'custom' with a descriptive custom event name.
After installing, add or update tests around the integration points, then run the relevant test/build command for this app. Use this section when you or the coding agent need the exact SDK shape.
Use identify to attach durable user, organisation, and plan context to every identity.
Userbook standard events must use the supported event names below. The SDK sends standard events by default; direct API calls should include type: 'standard'.
Use custom events for product behavior that is important to your app but is not one of the standard lifecycle events.
Use cost and currency when a specific event has direct monetary value.