> ## 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.

# Send funnel steps from your server

> Send funnel steps that only your server knows about, such as payments from a Stripe webhook, with a secret key and the server SDK.

Some funnel steps happen only on your server: a payment succeeds in a Stripe webhook, a subscription renews, a background job finishes. Send them with a secret key and they appear in the same funnel as the user's browser steps.

Server steps join browser steps by user ID. Call `Wendung.identify(userId)` in the browser and send the same ID from your server. Server steps for anonymous visitors, before they sign up, are not supported.

## Create a secret key

1. Open the project's **Settings → API keys** and click **Add API key**.
2. Choose **Secret key** and give it a name, such as `Billing webhooks`.
3. Copy the key. Wendung stores only a hash of it, so it is shown once.
4. Add it to your server environment, for example as `WENDUNG_SECRET_KEY`.

Secret keys start with `sk_`. Never put one in frontend code: ingest rejects any request that uses a secret key from a browser with HTTP `403` and the reason `secret_key_in_browser`. If a secret key was exposed, delete it in settings and create a new one.

Agents connected through the [Wendung MCP server](https://docs.wendung.app/agents.md) can't create or reveal secret keys. They see them masked, so the key never passes through the agent.

## Send a step from Node.js, Workers, or edge functions

Install the SDK and import the server entry point. It uses only `fetch`, so it runs on Node.js 18 or newer, Cloudflare Workers, Vercel Edge Functions, and Deno. Full reference: [`WendungServer`](https://docs.wendung.app/api-reference/server).

```bash theme={null}
npm install @wendung/sdk
```

```ts theme={null}
import { WendungServer } from '@wendung/sdk/server'

const wendung = new WendungServer({
  secretKey: process.env.WENDUNG_SECRET_KEY!,
})

// In your Stripe webhook handler, after verifying the event:
await wendung.step('payment_succeeded', {
  id: event.id,
  userId: appUserId,
  timestamp: new Date(event.created * 1000),
  properties: { plan: 'pro' },
})
```

`appUserId` is the ID you pass to `identify()` in the browser. Look it up from your own records, for example from metadata you stored on the Stripe customer.

`step()` waits until ingest accepts the step. It retries rate limits, server errors, and network failures up to three attempts with backoff, and your handler waits through those retries before it responds. It never throws, so a Wendung error or an invalid timestamp can't fail your webhook. It returns `{ ok: true, status }` on success and `{ ok: false, status, error }` otherwise, and logs failures with `console.warn`. Pass `debug: true` to also log accepted steps. The `WendungServer` constructor does throw if the secret key is missing or doesn't start with `sk_`.

| Field | Rules |
| - | - |
| Step name | 1 to 100 characters. Names that start with `$` are reserved. |
| `id` | Required. Up to 100 characters. Use the source event's own ID so a retried webhook is stored once. |
| `userId` | Required. The same ID you pass to `identify()` in the browser. Up to 255 characters. |
| `timestamp` | Required. When the step happened, at most 7 days ago and at most 5 minutes in the future. |
| `properties` | Optional. Up to 20 top-level keys. |

## Send a step over HTTP

From other languages, send a `POST` request to the ingest endpoint with the secret key in the `X-API-Key` header and no `Origin` header. One request carries up to 100 events.

```bash theme={null}
curl https://ingest.wendung.app/v1/events \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $WENDUNG_SECRET_KEY" \
  -d '{
    "events": [
      {
        "id": "evt_1Q2w3E4r5T6y",
        "name": "payment_succeeded",
        "userId": "user_0042",
        "timestamp": "2026-11-20T10:00:00.000Z",
        "properties": { "plan": "pro" }
      }
    ]
  }'
```

Ingest answers `202` with `accepted`, `batchId`, and `requestId`. Retry `429` and `5xx` responses with backoff. Don't retry other `4xx` responses: the request will fail the same way again.

## Retries and duplicates

Wendung stores an event once per project, event ID, step name, and timestamp. A retry with the same `id` and `timestamp` replaces the earlier copy instead of adding a second one. A retry with a new timestamp, such as the time the retry ran, is stored as a separate event and counted twice. That is why `timestamp` should come from the source event, not from the current time.

## How server steps appear in reports

A server step has no browser, device, location, or traits of its own. For filters and segment breakdowns, Wendung uses the context of the user's most recent browser event at or before the server step: country, city, device, browser, operating system, source, plan, and traits.

* A user who signs up on a phone and pays from a webhook counts as a mobile user at the payment step, even if they later visit on a laptop.
* Wendung looks for that context in the selected date range. In some reports, such as conversion trends and step timing, it looks only at events that are steps of the same funnel.
* If no browser event comes before the server step in that range, the step's context is unknown. Filters on device, location, source, plan, or traits leave it out.
* Property filters apply to the server step's own `properties`.

On the [Events page](https://docs.wendung.app/help/events.md), server requests show **Server** as their origin. On the Users page with a device or location filter, a user's server steps are not included in their event counts.

## Consent

Server steps don't pass through the browser SDK's consent state. You decide whether you may record a step for that user under the rules that apply to you. If a user declined analytics in your consent manager, skip `step()` for them on the server too. Wendung does not store consent choices. See [Consent](https://docs.wendung.app/guides/consent.md).

## Limits

* Server steps count toward the workspace's monthly event quota on every plan, including Free.
* Secret keys have their own rate limit bucket at the plan's rate, separate from the project's browser traffic. See [Plans and limits](https://docs.wendung.app/help/plans.md).

## Errors

Rejected requests appear on the [Events page](https://docs.wendung.app/help/events.md) with their reason.

| Status | Reason | What to do |
| - | - | - |
| `401` | `invalid_api_key` | The key is wrong, inactive, or deleted. Create a new secret key. |
| `403` | `secret_key_in_browser` | Move the call to your server and use the publishable key in the browser. |
| `400` | `payload_does_not_match_api_key` | Use the server payload above with secret keys, and the browser SDK with publishable keys. |
| `400` | `timestamp_out_of_range` | Send the source event's time, within 7 days of now. |
| `400` | `reserved_event_name` | Rename the step so it doesn't start with `$`. |
| `400` | `invalid_payload` | Check that every event has `id`, `name`, `userId`, and `timestamp`. The only other allowed field is `properties`. |
| `429` | `rate_limited`, `event_quota_exceeded` | Retry with backoff, or wait for the quota to reset. |


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