> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wendung.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Add funnel analytics to a Next.js app with Claude Code

> Have Claude Code add Wendung to a Next.js App Router project from one prompt, check that events arrive, and then ask it where users drop off.

Claude Code can add Wendung to a Next.js app from a single prompt. It reads your codebase, proposes funnel steps, and changes files only after you approve the plan. Your part is the account, the publishable key, the plan approval, and the allowed origins in the dashboard. Once events arrive, you can connect Claude Code to your analytics and ask it which step loses users.

To write the code yourself instead, follow the [Next.js guide](https://docs.wendung.app/guides/nextjs.md).

## What you need

* A Next.js project using the App Router. The setup also handles Pages Router and other frameworks, but this guide follows the App Router.
* [Claude Code](https://code.claude.com/docs/en/overview) running in the project's folder.
* A Wendung account. [Sign up](https://dashboard.wendung.app/auth/sign-up) without a card; your first workspace starts a 14-day trial of the Starter plan and then moves to the Free plan. See [Plans and limits](https://docs.wendung.app/help/plans.md).

## Setup

**1. Create a project and copy its key**

In the dashboard, create a project for the app. Open the project's **Settings → API keys** and copy the key named **Default**. It starts with `pk_`. A publishable key is safe in frontend code, and ingest accepts it only from your allowed origins, so you can paste it into the chat.

A new project starts with [Dev mode](https://docs.wendung.app/help/settings.md#dev-mode) on, so it accepts events from localhost for its first 24 hours. If your project is older, turn on Dev mode under **Settings → Allowed origins**. It can take a few minutes to take effect.

**2. Run the setup prompt**

Paste this prompt into Claude Code:

```text Prompt theme={null}
Read https://docs.wendung.app/setup.md and follow it to set up Wendung in this project.
```

Claude Code asks whether you have an account, a project, and the key, and whether Dev mode is on. Answer in one message. It then installs the `wendung-sdk` skill, which documents the SDK's API so it can follow it instead of guessing method names or options. The [setup prompt](https://docs.wendung.app/setup) lists every step it follows.

**3. Review the plan**

Before it edits any file, Claude Code reports what it found and proposes a funnel. For a typical SaaS app, the plan looks like this:

| Step | Where it happens |
| - | - |
| `signup_completed` | The sign-up form, after the account is created |
| `onboarding_completed` | The last onboarding screen |
| `checkout_started` | The upgrade button, before the redirect to Stripe |
| `payment_succeeded` | The Stripe webhook, as a server step |

Check that each step marks a moment that matters to you and that the names are what you want to see in reports. Names are matched character for character, so changing them later means changing the code and the funnel.

Claude Code also asks two things you decide:

* **Pageviews.** Whether to turn on pageview tracking for web analytics. The Free plan doesn't include pageviews.
* **Consent.** How your app asks visitors for consent to analytics and restores their choice. If you have no consent banner yet, say so; the [consent guide](https://docs.wendung.app/guides/consent.md) covers the options.

Steps that happen only on your server, such as a payment confirmed by Stripe, need a secret key that you create in the dashboard and add to the server environment yourself. The setup prompt tells Claude Code not to ask for it in the chat. See [Track Stripe payments as funnel steps](https://docs.wendung.app/guides/stripe-payments.md).

**4. Approve and let it add the code**

After you approve the plan, the setup prompt tells Claude Code to:

* install `@wendung/sdk` and read the key from an env var,
* call `Wendung.init()` once in the browser, with `debug` on in development,
* set `consent` for the setup you chose and, if your app waits for the visitor's choice, connect `setConsent()` to your consent manager,
* call `identify()` when the user is known and consent is granted, including after a signed-in user grants consent, and `reset()` on logout,
* add each `step()` call where its milestone happens,
* run your build, type check, and lint.

In a Next.js App Router project this usually ends up like the [Next.js guide](https://docs.wendung.app/guides/nextjs.md): a client provider in the root layout. Review the diff like any other change.

**5. Allow your app's origins**

In the project's **Settings → Allowed origins**:

* Add your production origin, for example `https://app.example.com`.
* Turn [Dev mode](https://docs.wendung.app/help/settings.md#dev-mode) back on if it has switched off. It accepts events from localhost for 24 hours.

**6. Check that events arrive**

Run the app locally, accept analytics in your consent banner if the app has one, and trigger one of the steps, for example by signing up a test user. With `debug` on, the browser console logs `[Wendung] ingest accepted batch`. The project's [Events page](https://docs.wendung.app/help/events.md) lists each request with its status. A rejected request shows the reason, such as an origin that isn't allowed.

**7. Create the funnel**

Under **Funnels**, create a funnel and pick the step names in order. Names that have already arrived appear in the step picker with their counts. See [Creating a funnel](https://docs.wendung.app/help/funnels.md#creating-a-funnel). The Free plan includes one funnel per project.

## Ask Claude Code where users drop off

Once real traffic has passed through the funnel, connect Claude Code to your Wendung data:

```bash theme={null}
claude mcp add --transport http wendung https://api.wendung.app/mcp
```

In Claude Code, run `/mcp`, select `wendung`, and sign in to Wendung in the browser window that opens. New connections get read access by default.

Then ask questions that combine your data with your code, for example:

```text Prompt theme={null}
Which step of my signup funnel lost the most users in the last 7 days?
Compare mobile and desktop, then look at the code for that step and
tell me what could cause the drop.
```

Claude Code reads the funnel, segment, and user timeline data through the MCP server and the code from your project, so it can relate the drop to the code behind that step and propose a change in the same session. [Find and fix funnel drop-off with your coding agent](https://docs.wendung.app/guides/fix-drop-off-with-your-agent.md) walks through a full investigation. Each analytics query counts toward your plan's monthly MCP queries; listing funnels and cached results don't. The Free plan includes 50.

To also let Claude Code search these docs, add the public docs server:

```bash theme={null}
claude mcp add --transport http wendung-docs https://docs.wendung.app/mcp
```

[Agent setup](https://docs.wendung.app/agents.md) covers other agents, write access, and a prompt that connects both servers at once.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.