Skip to main content
Use Next.js’s built-in next/script component. It de-duplicates the script across client-side navigations and gives you control over when it loads.
1

Add the script to the root layout

Place it once, in the root layout, so it loads for every route.
app/layout.tsx
strategy="afterInteractive" (the default) loads the script after hydration, which is right for the SDK. Don’t use beforeInteractive — the SDK isn’t needed before your app is interactive, and that strategy blocks other scripts.
The Pages Router works the same way: put the <Script> in pages/_app.tsx.
2

Add type declarations

Declare the global so you can use window.CashbackHive without any. Copy the complete declaration file from the Types reference into your project, for example at types/cashback-hive.d.ts.Make sure the file is included by your tsconfig.json (the default "include": ["**/*.ts", "**/*.tsx"] covers it).
3

Create a readiness hook

Components render during hydration, before afterInteractive scripts run, so a simple useEffect listener usually works — but a component that mounts after a client-side navigation would wait forever for an event that already fired. useSyncExternalStore handles both cases cleanly and satisfies the React Compiler lint rules.
hooks/use-cashback-hive.ts
4

Use it in a client component

components/offers.tsx
Server Components can’t access window, so anything that calls the SDK must be a Client Component ("use client"). You can still render the Client Component from a Server Component page.

Environment variables

If you prefer not to hardcode the key, read it from a NEXT_PUBLIC_ variable. This is safe only for the publishable key.
Never put a secret key in a NEXT_PUBLIC_* variable — those are inlined into the client bundle.

Content Security Policy

If your app sets a CSP (via next.config.js headers or middleware), add https://sdk.cashbackhive.com to script-src and connect-src. See Content Security Policy.

Complete example

A working Next.js App Router integration — layout, hook, types, and Offers/Activate widgets — is in the Widgets section.