Setup
1
Install the SDK
Add Then add your publishable key to Your key is under Settings → API Keys in the dashboard.
@wendung/sdk to your project..env.local:.env.local
2
Create a provider component
Create
app/providers/wendung-provider.tsx. It initializes the SDK once on mount and tears it down on unmount.app/providers/wendung-provider.tsx
init() is idempotent. If an instance is already running, as happens under React Strict Mode or Fast Refresh, it is torn down before the new one starts, so there are no duplicate flushes or listeners.3
Add the provider to your root layout
Wrap your app’s
children with <WendungProvider> in app/layout.tsx.app/layout.tsx
layout.tsx can remain a server component. Only WendungProvider itself needs 'use client'.4
Track funnel steps
Call
step() from any client component to record an event. The name should match a step in one of your funnels. The optional second argument is a plain object of properties.app/components/signup-form.tsx
5
Identify users
Identify a user as soon as you know who they are, usually right after login. The cleanest pattern is a small client component that reads the session and calls Drop
identify() once:app/providers/wendung-identity.tsx
<WendungIdentity /> inside <WendungProvider> in your layout. It runs once the session is available and re-identifies if the user changes.If your auth flow is fully client-side, you can also call identify() from your login handler. Use whichever fits your stack.6
Turn on pageview tracking
Next.js App Router does not trigger a full page load between routes. With For aggregate pageviews while consent is pending, use
trackPageviews: true the SDK records the initial load and every client-side navigation, so route tracking needs no code of your own:app/providers/wendung-provider.tsx
trackPageviews: 'auto' and pass the current consent state. Call Wendung.setConsent('granted') to switch to full analytics, or 'denied' to stop collection. See the consent guide for saving and restoring the choice.Register the hostname under Sites in the dashboard to see the traffic. Pageviews use a separate monthly allowance from events; see the web analytics guide.7
Handle logout
Call
reset() when the user signs out. It flushes pending events under the old identity, clears the user ID and traits, and starts a new session.app/components/logout-button.tsx
Server Components and Server Actions
The SDK is browser-only. Don’t call it from Server Components, Route Handlers, or Server Actions. Importing it there is harmless, but calling it is not a supported path: the browser lifecycle hooks never run, and a server runtime withfetch may still fire network requests. To record an event that results from a server action, either:
- Return a signal from the action and call
step()in the client component that invoked it, or - Call
step()optimistically before invoking the action.
Using Pages Router?
The setup is similar: initialize inpages/_app.tsx inside a useEffect, and use router.events from next/router for route-change tracking. A dedicated Pages Router guide is coming; for now, the Quickstart covers the core flow.
What’s next
Create your first funnel
Turn your tracked step names into a funnel in the dashboard.
API reference
Every option accepted by
init(), identify(), step(), and reset().