Next.js | App router

Client Side Rendering

Intelligems currently recommends using client-side rendering rather than SSR for Next.js App Router integrations to keep the implementation simple and avoid hydration mismatches.

Environment Variables

Add the following to your .env file:

NEXT_PUBLIC_INTELLIGEMS_ORG_ID=<Intelligems-ID>
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=<Storefront-API-Token>

Provider Integration

The IntelligemsNextClientsideAppDirectoryProvider component stores Intelligems data in React Context so hooks and components can access it throughout your app.

Integration Example

IntelligemsProvider

Create IntelligemsProvider:

"use client";

import { IntelligemsNextClientsideAppDirectoryProvider } from "@intelligems/headless/next-clientside-app-directory";

export function IntelligemsProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <IntelligemsNextClientsideAppDirectoryProvider
      organizationId={process.env.NEXT_PUBLIC_INTELLIGEMS_ORG_ID}
      storefrontApiToken={
        process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN
      }
      activeCurrencyCode="USD" // Must be provided
      antiFlicker={true}
    >
      {children}
    </IntelligemsNextClientsideAppDirectoryProvider>
  );
}

RootLayout

Insert IntelligemsProvider inside your RootLayout:

Page Views Tracking

useIgTrack is a client-side hook tracking page views.

To provide accurate analytics ensure it is configured with valid parameters:

  • cartOrCheckoutToken

  • currency

  • country

Create a client component

Render it inside your provider wrapper

Last updated