Skip to main content

Next.js Integration

The Solute SDK provides first-class support for Next.js App Router with React hooks, server-side utilities, and middleware.

Setup

1. Install the SDK

2. Create Provider Wrapper

Create a client component wrapper for the provider:

3. Add to Root Layout

React Hooks

Use hooks in client components to access SDK functionality.

useTrack

Track events in client components:

useIdentify

Identify users:

useFeatureEnabled

Check if a feature is enabled:

useExperiment

Get A/B test variant:

useUser

Get user information:

useSolute

Access the full SDK instance:

Server-Side Utilities

Use server-side utilities in Server Components and API routes.

trackServerEvent

Track events on the server:

getServerFeatureFlag

Get feature flags on the server:

getServerExperimentVariant

Get experiment variant on the server:

Middleware

Set up automatic page view tracking with middleware:

Environment Variables

Set up environment variables:
Use NEXT_PUBLIC_ prefix for client-side environment variables. Server-side variables don’t need the prefix.

Best Practices

React hooks can only be used in client components. Make sure to add 'use client' directive.
Use server-side utilities in Server Components and API routes for better performance.
Use different environment variables for client and server to keep API keys secure.
Wrap your app with SoluteProvider at the root layout level to ensure hooks work everywhere.

Next Steps

Server-Side Tracking

Learn about server-side tracking

API Reference

Complete API reference