@signal-sparrow/next
v0.1.1
Published
Next.js wrapper for the Signal Sparrow tracking SDK
Readme
@signal-sparrow/next
The official Next.js wrapper for the Signal Sparrow tracking SDK. It initializes @signal-sparrow/sdk once and automatically tracks page views across Next.js App Router navigations.
Installation
npm install @signal-sparrow/nextPeer dependencies: next@^16, react@>=18, and react-dom@>=18.
Quick start
Wrap your app in RevenuePixelProvider (a client component). In the App Router, add it to your root layout:
// app/layout.tsx
import { RevenuePixelProvider } from '@signal-sparrow/next';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<RevenuePixelProvider publicKey="pk_live_YOUR_PUBLIC_KEY">
{children}
</RevenuePixelProvider>
</body>
</html>
);
}The provider initializes the SDK once and emits a PageView on every route change. Get your public key from your Signal Sparrow dashboard — it is safe to expose in the browser.
Provider props
| Prop | Type | Description |
| --- | --- | --- |
| publicKey | string | Required. Your site's public key (pk_live_…). |
| endpoint | string | Optional. URL that events are sent to. |
| consentMode | 'anonymous' \| 'hold' | Optional. Tracking behaviour before consent — see the core SDK. |
| children | ReactNode | Your app. |
Hooks
Prefer hooks when you want more control than the provider offers.
useRevenuePixel(options) — initializes the SDK once and returns { track, identify, setConsent }.
'use client';
import { useRevenuePixel } from '@signal-sparrow/next';
export function CheckoutButton() {
const { track } = useRevenuePixel({ publicKey: 'pk_live_YOUR_PUBLIC_KEY' });
return <button onClick={() => track('CheckoutStarted')}>Checkout</button>;
}usePageViews() — emits a PageView on every App Router pathname change (it skips the initial load, which the SDK already captures on init). Used internally by RevenuePixelProvider.
useIdentify() — returns the identify(emailOrUserId) function.
useSetConsent() — returns the setConsent(granted) function for wiring up consent management.
serverEventId(conversionEventId, destinationType) — returns a deterministic event id used to deduplicate a browser event against its server-side Conversions API counterpart.
Core SDK
This package configures and re-exports @signal-sparrow/sdk. See its README for the full configuration options, consent modes, and the list of advertising identifiers captured automatically.
License
MIT © Signal Sparrow. See LICENSE.
