> ## 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 v0 app

> Ask v0 to add Wendung to your Next.js app with one prompt, set the key for preview and production, allow both addresses, and check that funnel steps arrive.

v0 can add Wendung to your app from a single chat prompt. It installs `@wendung/sdk`, adds a funnel step at each moment you want to measure, and reads your key from an environment variable. Your part is the account, the key, approving the plan, and adding your app's addresses to the project's allowed origins.

v0 runs your app's preview on a hosted address, not on localhost. [Dev mode](https://docs.wendung.app/help/settings.md#dev-mode), which accepts localhost for a new project's first 24 hours, doesn't cover it, so every address your app runs on must be on the allowed origins list before its events are accepted.

## What you need

* A v0 project. v0 builds Next.js apps with the App Router by default, and this guide assumes one.
* 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 Wendung 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.

**2. Add the key as an environment variable**

In v0, open the project menu **...** and go to **Settings → Environment Variables**. Add a variable named `NEXT_PUBLIC_WENDUNG_KEY` with your key as the value. Next.js exposes only variables that start with `NEXT_PUBLIC_` to browser code.

Make the variable available to both of these environments:

* **Development**, which the v0 preview reads.
* **Production**, which your published app reads.

**3. Send the prompt**

Send this prompt in the v0 chat:

```text Prompt theme={null}
Add Wendung funnel analytics to this app with the @wendung/sdk npm package.
The full SDK reference is at https://docs.wendung.app/skills/wendung-sdk.yaml.
Follow it instead of guessing method names or options.

Before you change any files, propose a plan and wait for my approval:
- funnel steps as snake_case, past-tense names such as signup_completed,
  with the file and the moment each one happens
- whether visitors must accept analytics before tracking starts
- whether to track pageviews (leave them off unless I ask)

After I approve:
1. Install @wendung/sdk and import it as
   import { Wendung } from '@wendung/sdk'.
2. Read the key from process.env.NEXT_PUBLIC_WENDUNG_KEY. It is already set
   in the project's environment variables.
3. Call Wendung.init() once, in a 'use client' provider component that runs
   it in useEffect, and wrap children with it in app/layout.tsx. Never call
   Wendung from Server Components, Route Handlers, or Server Actions. Pass
   apiKey, consent, and debug: true in development.
4. If visitors must accept first, start with consent: 'pending', pass the
   saved choice on every load, and call Wendung.setConsent() from the
   consent banner. Otherwise pass consent: 'granted'.
5. Call Wendung.identify(userId) when the user is signed in and consent is
   granted, including after a signed-in user grants consent, and only after
   init() has run. Call Wendung.reset() on logout.
6. Add each Wendung.step() call where its milestone happens, only after
   init() has run.
7. If I ask for pageviews, pass trackPageviews: true in init(), or 'auto'
   for aggregate pageviews while consent is pending.
```

The prompt lists the rules that matter most, in case v0 doesn't open the link to the SDK reference. The provider follows the pattern in the [Next.js guide](https://docs.wendung.app/guides/nextjs.md).

**4. Review the plan**

The prompt asks v0 to propose a funnel before it edits any file. If it starts editing right away, stop it and ask for the plan. 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 checkout |

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.

Decide the two open questions:

* **Consent.** If visitors must accept analytics first and your app has no consent banner yet, ask v0 to add one. The [consent guide](https://docs.wendung.app/guides/consent.md) explains the options.
* **Pageviews.** Pageview tracking adds web analytics for the app's pages. The Free plan doesn't include pageviews. To see them, register the published address under **Sites**; see [Web analytics](https://docs.wendung.app/guides/web-analytics.md).

Then reply that you approve the plan.

**5. Allow the preview's address**

Open the preview, accept analytics in the consent banner if your app has one, and complete one of the steps, for example by signing up a test user.

The first request is rejected because the preview's address isn't on the list yet. In the Wendung dashboard, open the project's [Events page](https://docs.wendung.app/help/events.md). The request shows the status **Rejected** and, in the **Origin** column, the address it came from. Copy that origin and add it under **Settings → Allowed origins**.

Allowed origins match exactly, and v0 sets the preview's address. If preview events stop arriving later, check the Events page for a rejected request from a new origin and add it too.

**6. Check that events arrive**

Origin changes can take a few minutes to reach the ingest endpoint. Then complete the step again in the preview. The Events page lists the new request as **Delivered**.

Events from the preview are stored in the same project as events from your published app, so your test steps count in your funnels.

**7. Publish and allow the published address**

Select **Publish** in the chat header. v0 deploys the app to Vercel, and the project gets a stable production address ending in `vercel.app`. You can add a custom domain under **Settings → Domains**.

Add each address your published app uses under **Settings → Allowed origins** in Wendung, for example `https://your-app.vercel.app` and `https://www.example.com`. Each one is a separate entry. Then complete a step on the published app and confirm it on the Events page.

If your project is connected to GitHub, each preview deployment of a working branch gets its own unique address. Add one only if you want to track events from it. Its key comes from the **Preview** environment, so add `NEXT_PUBLIC_WENDUNG_KEY` there too.

**8. 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.

## Steps that happen on the server

A payment confirmed by a webhook happens on the server, not in the visitor's browser. Sending it as a funnel step needs a secret key (`sk_`), which you create in the dashboard. Add it as an environment variable without the `NEXT_PUBLIC_` prefix, such as `WENDUNG_SECRET_KEY`, so it stays on the server. See [Server-side events](https://docs.wendung.app/guides/server-events.md) and [Track Stripe payments as funnel steps](https://docs.wendung.app/guides/stripe-payments.md).

## Troubleshooting

* **No request on the Events page.** The key is missing or wrong, or no step ran. Check that `NEXT_PUBLIC_WENDUNG_KEY` holds your project's `pk_` key in the environment you're testing, and that you completed a step after accepting analytics.
* **Works in the preview but not after publishing.** The variable is missing from the Production environment, or the published address isn't an allowed origin. Add the variable and publish again, because Next.js reads `NEXT_PUBLIC_` values when it builds the app. A missing origin shows up on the Events page as a rejected request.
* **Requests rejected because the origin isn't allowed.** Add the exact origin shown on the Events page, including `https://` and the full subdomain.
* **Requests rejected with `rate_limited` or `event_quota_exceeded`.** The project reached a [plan limit](https://docs.wendung.app/help/plans.md).

[Debugging](https://docs.wendung.app/configuration/debugging.md) covers each rejection status and the SDK's console messages, and the [Events page](https://docs.wendung.app/help/events.md) explains each rejection reason.


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