Identify Users

identify() is the entry point that turns an anonymous browser session into a known user. It must be called before track(), getInAppContent(), or reportAction().

Signature

identify(
  externalUserId: string,
  attributes?: Record<string, unknown>,
): Promise<void>

When to call it

  • Right after login — once you know who the user is.
  • On every page load for already-authenticated users — cheap, idempotent, and refreshes the session token.
  • Never in a tight loop — the call hits the server. Identify once per page or per login event.

Example

await treliq.identify('user_123', {
  email: '[email protected]',
  name: 'Jane Doe',
  plan: 'pro',
  signed_up_at: '2024-01-15',
});

The first argument — the external user ID — is the stable identifier from your system (database row ID, UUID, email, anything you trust to be unique and unchanging). Treliq maps it to an internal end-user ID and remembers the association for future calls.

Attributes

The optional second argument is a flat object of user attributes. Treliq stores these on the end-user record and makes them available to your workflows for branching, filtering, and personalization.

Recommended attributes:

AttributeWhy
emailRequired for any email-driven workflow
name / first_namePersonalization in messages
plan / tierPlan-based segmentation
created_atLifecycle workflows (“welcome on day 7”)
locale / timezoneTime-zone-aware delivery

You can also pass arbitrary product-specific attributes (organization_id, team_size, feature_flags, etc.).

What happens under the hood

  1. The SDK POSTs { project_id, external_user_id, attributes } to /v1/engine/sdk/ingest.
  2. The server upserts the end-user record and issues a session token.
  3. The response may include pending_content — in-app messages queued for this user from previous workflow runs. The SDK renders them immediately if inApp.enabled is true.
  4. The SDK opens a WebSocket connection (if sseUrl is configured) or starts a 30-second polling loop to receive new in-app content as workflows execute.

Retry behavior

If the identify call is rate-limited (HTTP 429), the SDK retries up to 3 times with the server’s Retry-After header (capped at 10 seconds). All other errors throw immediately and trigger onError if configured.

Re-identifying

Calling identify() with a different externalUserId re-authenticates the session as that user. Calling it with the same ID and updated attributes refreshes the user record:

// Update plan after upgrade
await treliq.identify('user_123', { plan: 'enterprise' });