💎
Headless Docs
Version 0.2.0
Version 0.2.0
  • Overview
  • Change Log
  • Next.js Steps
    • Requirements
    • Determine Page Methods
      • Route Hashing Method
      • Cookies Method
    • Install Middleware
    • Add Intelligems Provider
    • Read User Context
      • Route Hashing Method
      • Cookies Method
    • Track Page Views
    • Update Prices on Page
    • Update ATC Events
    • Preview Your Site
  • Gatsby Steps
    • Requirements
    • Add Intelligems Provider
    • Track Page Views
    • Update Prices on Page
    • Update ATC Events
    • Preview Your Site
  • Pack Digital Steps
    • Requirements
    • Add Intelligems Provider
    • Track Page Views
    • Update Prices on Page
    • Update ATC Events
    • Preview Your Site
  • Examples
    • Content Testing
  • Reference
    • Middleware Objects
      • IgMiddlewareConfig
      • IgMiddlewareHandler
    • Providers
      • Next.js
      • Gatsby
    • Components
      • Price Components
    • Hooks
      • Price Hooks
      • Track Hooks
      • Experiment Hooks
      • Test Group Hooks
      • Cart & Checkout Hooks
Powered by GitBook
On this page
  • How it Works
  • Add Intelligems To Middleware
  • Example Configuration
  1. Next.js Steps

Install Middleware

PreviousCookies MethodNextAdd Intelligems Provider

How it Works

Intelligems uses to split and assign visitors into a Test Group for each active Test and adds this User Context to browser cookies.

  • If using the , this user context is passed to page props directly through a URL hash.

  • If using the , this user context is saved as cookies and read at response time.

Add Intelligems To Middleware

Example Configuration

import { IgMiddlewareHandler } from '@intelligems/headless/next'
import type { IgMiddlewareConfig } from '@intelligems/headless/next'

const igConfig: IgMiddlewareConfig = {
  settings: {
    enabled: true
    orgId: process.env.NEXT_PUBLIC_INTELLIGEMS_ORG_ID!,
    cacheIntervalMinutes: 5,
  },
  routes: {
    forceSkipRoutes: [
      '/api',
      '/_next',
      '/orders',
      '/profile',
      '/wishlist',
      '/favicon',
    ],
    getServerSidePropsRoutes: ['/', '/search'],
    getStaticPropsRoutes: ['/product/:path'],
  },
}

export async function middleware(req: NextRequest) {
  const igMiddlewareHandler = new IgMiddlewareHandler(req, igConfig)

  const res = NextResponse.next()
  await igMiddlewareHandler.setContext(res)
  return res
}
Next.js middleware
Route Hashing Method
Cookies Method
directions
method
IgMiddlewareConfig
IgMiddlewareHandler