Identity
Attribute activity to a user instead of a device — identify, setUser, clearUser, and what happens to data captured before sign-in.
Before you identify anyone, activity is attributed to a device. After, it is attributed to a user.
Identify after sign-in#
ScaleBun.identify('user_123', { plan: 'pro', email: 'ada@example.com', signupDate: '2026-01-14',});The first argument is your own stable user id. Use whatever your backend considers canonical — a database id or UUID. The traits object is optional and merges with whatever is already stored.
Calling identify before init#
Safe. Identity is buffered and applied once init() completes, so you do not need
to order the two calls or await initialisation before you can identify.
ScaleBun.identify('user_123'); // bufferedawait ScaleBun.init({ /* … */ }); // identity applied hereClear on sign-out#
ScaleBun.clearUser();Call this on every sign-out. Skipping it on a shared device attributes the next person's activity to the previous user — which corrupts retention and funnel numbers in a way that is very hard to notice later.
clearUser() does not reset the device id. The device remains the same device;
it simply stops being associated with that user.
setUser vs identify#
Both establish identity. They differ in shape:
identify(userId, traits?) | setUser(user) | |
|---|---|---|
| Shape | Two arguments | One ScaleBunUser object |
| Fields | Any traits | id, name, email, attributes, properties |
| Use when | Normal application flow | You already hold a user object |
ScaleBun.setUser({ id: 'user_123', name: 'Ada Lovelace', email: 'ada@example.com', attributes: { plan: 'pro', seats: 12 },});identifyUser() also exists and behaves as identify() does; prefer identify()
in new code.
Advertising and attribution identifiers#
Attribution needs device identifiers, which are separate from user identity and gated by platform consent. Supply them once you have permission:
ScaleBun.events.setIdentifiers({ idfa, gaid, idfv });Requesting consent is your app's responsibility — the SDK never prompts on your behalf, because the prompt's timing and copy affect your opt-in rate and belong to your product.
For deferred deep-link attribution, record the click token:
ScaleBun.events.setAttributionClickId(clickId);Replay identity#
Session replay keeps its own identity so it can be switched off independently of analytics:
ScaleBun.replay.setUser({ id: 'user_123' });ScaleBun.replay.clearUser();If you use both, set both — identifying for analytics does not name the user on a replay.
Deleting a user's data#
Deletion is a server-side operation, not an SDK call. clearUser() stops
attribution going forward; it does not remove anything already captured. Use the
GDPR/CCPA data-request endpoints in the API reference to
erase a user.
Related#
Events — attaching events to an identified user.
Core concepts — device versus user attribution.
Methods — full signatures.