Skip to main content

Installation

Quick start

Wrap your app with OutlitProvider and use the useOutlit hook in components.

Using the hook

Track custom events with the useOutlit hook:

Provider configuration

OutlitProvider

The OutlitProvider initializes tracking and provides context to child components.

Props

string
required
Your organization’s public key.
string
default:"https://app.outlit.ai"
API endpoint for sending events.
boolean
default:"true"
Automatically track pageviews on route changes.
boolean
default:"true"
Automatically capture form submissions.
string[]
Additional field names to exclude from form capture.
number
default:"5000"
How often to flush queued events (ms).
boolean | "auto"
default:"\"auto\""
Controls when tracking starts. "auto" (default) asks the Outlit edge endpoint whether the visitor’s region requires opt-in consent: tracking enables automatically outside the EEA, UK, and Switzerland, and stays off in those regions or when the region can’t be determined. The check fails closed on errors. true enables immediately; false waits for enableTracking() from the useOutlit hook. isTrackingEnabled updates automatically when auto mode enables tracking asynchronously.
boolean
default:"true"
Automatically identify users when they submit forms containing an email field. Extracts email and name (first name, last name, full name) using field name heuristics. Set to false to disable and call identify() manually. See Auto-identify for details.
boolean
default:"true"
Track engagement metrics (active time on page). Emits engagement events on page exit and navigation.
number
default:"30000"
Idle timeout in milliseconds for engagement tracking. After this period of no user interaction, the user is considered idle.
boolean
default:"true"
Track booking events from calendar embeds (Cal.com, Calendly).
UserIdentity | null
Current user identity. When provided with email or userId, identifies the user. When null or undefined, clears the user identity. This is the recommended way to handle user identity in server-rendered apps.
Outlit
An existing Outlit instance to use instead of creating one internally. When provided, config props (publicKey, apiHost, etc.) are ignored and shutdown() is not called on unmount — the caller owns the instance lifecycle. Useful for sharing a single instance between imperative usage and React context.

Client mode

If you need to use the same Outlit instance both imperatively and via React context, pass an existing instance with the client prop:
When using client, the provider does not call shutdown() on unmount — you own the instance lifecycle. Config props like publicKey and trackPageviews are ignored.

User identity patterns

The user prop is the recommended way to handle user identity. It’s simpler and more reliable than manual identify() calls because:
  • Automatic lifecycle management: Login/logout transitions are handled automatically
  • No timing issues: Identity is set before any events are tracked
  • Cleaner code: No need for useEffect + identify() synchronization

Pattern 1: client-side auth (Clerk, Auth0, etc.)

For auth libraries that provide React hooks:

Pattern 2: server-side auth (NextAuth, Lucia, etc.)

For auth systems where session is available server-side, read the session in the Server Component and pass the resolved user into a client wrapper — OutlitProvider itself must render inside a client component (the package does not ship a 'use client' entry).
Which pattern should I use?
  • Client-side auth hooks (Clerk, Auth0): Use Pattern 1 with a client providers component
  • Server-side sessions (NextAuth, Lucia, custom JWT): Use Pattern 2 — resolve the session in the server layout, pass user into a client Providers wrapper
Both patterns work equally well - choose based on how your auth library provides user data. In the App Router, OutlitProvider (and useOutlit) must always render inside a component with 'use client'. When the user prop changes (login/logout), the provider automatically calls setUser() or clearUser() internally. You don’t need to call these methods manually. The default autoTrack: "auto" mode already keeps tracking off for visitors in regions that require opt-in consent (EEA, UK, Switzerland, or unknown). enableTracking() — typically wired to your consent banner’s accept action — is what grants consent and is persisted for future sessions. To wait for enableTracking() instead — unless a previous opt-in is stored:

With third-party CMPs

Hooks

useOutlit

The primary hook for tracking events and identifying users.

Returns

(eventName: string, properties?: object) => void
Track a custom event.
(options: IdentifyOptions) => void
Identify the current visitor.
(identity: UserIdentity) => void
Set the current user identity. Ideal for SPA authentication flows.
() => void
Clear the current user identity (on logout).
object
User identity namespace:
  • user.identify(options) - Identify the user
() => string | null
Get the current visitor’s ID. Returns null if tracking is not enabled.
boolean
Whether tracking is currently enabled. Will be false until enableTracking() is called when autoTrack is false, while the "auto" region check is pending, or when that check requires consent or fails.
() => void
Enable tracking. Call this after obtaining user consent. Needed when autoTrack is false, or in the default "auto" mode when the visitor’s region requires consent or the region check fails.
() => void
Disable tracking and flush any pending events. Use this when a user declines or revokes consent.
boolean
Whether the tracker is ready.

useTrack

A convenience hook that returns just the track function:

useIdentify

A convenience hook that returns just the identify function:

Activation event

Track your value milestone as an ordinary event once it succeeds:
Choose this event as your activation event in Outlit. The first matching event records activation once for each eligible resolved person and company, independently. Billing status comes from verified integrations such as Stripe. See Customer journey.

Framework examples

Next.js App Router

Next.js pages router

Remix

Remix renders the root component in the browser, so the provider can live directly in root.tsx (Remix has no server-only component boundary like the Next.js App Router). Use a VITE_-prefixed env var for the public key:

Common patterns

Track on mount

Track when a component mounts (e.g., page viewed):

Track form submission

Track custom form events:

Identify after auth

Prefer the user prop instead. The pattern below works, but using the user prop on OutlitProvider is cleaner and handles the lifecycle automatically. See User identity patterns above. If you can’t use the user prop (e.g., the provider is in a different part of the tree), you can sync manually:

TypeScript

Full TypeScript support is included:

Next steps

Server-side tracking

Track events from your backend

Identity resolution

Learn how visits and events link to people