Skip to main content

Server Utilities

Server-side utilities for tracking events and using feature flags in Next.js Server Components and API routes.
These utilities are for server-side use only. They cannot be used in client components.

trackServerEvent

Track an event from the server.
SoluteConfig
required
SDK configuration with API key and host.
string
required
Event name.
EventProperties
Optional event properties.
object
Optional context with userId and anonymousId.

Returns

Promise<void>

Example

getServerFeatureFlag

Get a feature flag value on the server.
SoluteConfig
required
SDK configuration with API key and host.
string
required
Feature flag key.
T
Default value if flag is not found.

Returns

Promise<T | undefined>

Example

isServerFeatureEnabled

Check if a feature is enabled on the server.
SoluteConfig
required
SDK configuration with API key and host.
string
required
Feature flag key.
boolean
Default value if flag is not found (defaults to false).

Returns

Promise<boolean>

Example

getServerExperimentVariant

Get an experiment variant on the server.
SoluteConfig
required
SDK configuration with API key and host.
string
required
Experiment key.
string
Default variant if experiment is not found.

Returns

Promise<string | undefined>

Example

getUserIdFromCookies

Get the user ID from cookies (server-side).

Returns

Promise<string | undefined>

Example

getAnonymousIdFromCookies

Get the anonymous ID from cookies (server-side).

Returns

Promise<string | undefined>

Example

getRequestContext

Get request context (user agent, IP, referer) from headers.

Returns

Promise<{ userAgent?: string; ip?: string; referer?: string }>

Example

Server-Side Tracking Guide

React Hooks