Configure & identity

configure, identify, reset, setPushToken, and setNotificationPreferences — initializing the SDK and managing the current user

Every integration starts here: configure initializes the SDK with your publishable key, identify attaches your user ID once someone signs up, and reset clears the identity on logout. The SDK is anonymous-first — everything works before identify is ever called, and the anonymous history merges when it is.

Pick your platform once — every code sample in the reference follows it.

configure

Initializes the SDK. Call once, as early as possible in your app's lifecycle — before any other Invitebase call. Generates (or restores) the anonymous ID from platform storage and, by default, starts inbound referral resolution.

ParameterTypeDescription
publishableKeystringYour publishable key (pk_test_… or pk_live_…). The prefix determines test vs live mode.
autoResolvebooleanRun inbound attribution automatically. Default true. Set false to control the moment yourself with resolveReferral().
debugLoggingbooleanLog SDK activity (named debug on Web and React Native). Default false.
invitebase.configure(publishableKey: string, options?: ConfigureOptions): void
lib/invitebase.ts
import invitebase from '@invitebase/js';

invitebase.configure(process.env.NEXT_PUBLIC_INVITEBASE_PUBLISHABLE_KEY, { debug: true });

export default invitebase;

Restores the anonymous ID from localStorage and immediately checks the current URL and stored cookie for an inbound referral code.

identify

Attaches your user ID to the current person and merges their anonymous history — attribution, events, and gate progress recorded before login all carry over. Idempotent: identifying the same user twice is a no-op, and every ordering of attribute → events → identify merges correctly. See Users & identity.

ParameterTypeDescription
user.idstringRequired. Your stable ID for this user.
user.emailstringOptional. Used for self-referral and disposable-email fraud checks.
user.namestringOptional. Privacy-safe display name shown to invitees ("You were invited by Andrew").
user.traitsmapOptional. Arbitrary properties.
invitebase.identify(user: InvitebaseUser): Promise<void>
await invitebase.identify({
  id: 'usr_123',
  email: 'dana@example.com',
  name: 'Dana',
});

Throws an SDK error on failure.

reset

Clears the current identity (and any stored referral code) and starts a fresh anonymous session. Call on logout.

invitebase.reset(): void

No parameters.

setPushToken

Forwards the device's push token so Invitebase can send referral push notifications directly to this device. This wires up the Invitebase-managed delivery mode — the default, chosen per app in Settings. If you bring your own push provider instead (planned, not yet available), you will not call this: device tokens stay on your side, and Invitebase will hand each notification to your backend as a notification.due webhook.

Register for remote notifications as usual, then call setPushToken any time after configure — the token attaches to the current user, anonymous or identified, and merges onto the identified user like everything else.

Tokens are stored per user, per device: a referrer with two devices gets the push on both. Call it again whenever the platform rotates the token — the stored token is kept current — and stale tokens are pruned automatically via APNs/FCM feedback. Delivery also requires your push credentials (APNs .p8 key for iOS, FCM service-account key for Android) uploaded in Settings.

ParameterTypeDescription
tokenData / stringThe APNs device token (iOS) or FCM registration token (Android).

Not applicable — Invitebase push delivery targets iOS and Android device tokens, so there is nothing to register on Web. Web users are still reachable by email.

setNotificationPreferences

Sets the current user's referral-notification preferences — whether Invitebase may email or push them about referral activity (triggers). Both channels default to on. Preferences are stored server-side per user, checked before every dispatch, and survive re-identification and new devices. Set for an anonymous user, they merge onto the identified user like everything else.

ParameterTypeDescription
preferences.emailbooleanAllow referral emails. Default true.
preferences.pushbooleanAllow referral push notifications. Default true.

Omitted channels are left unchanged, so a single toggle can flip one channel without touching the other.

invitebase.setNotificationPreferences(preferences: NotificationPreferences): Promise<void>
await invitebase.setNotificationPreferences({ email: false, push: true });

Throws an SDK error on failure. The same preferences are settable server-side via POST /v1/referrers.

What's next

On this page