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

# Wendung.init(): Initialize and configure the Wendung SDK

> Configure and start the Wendung SDK. Call once from client-side app startup before using any other method.

Call `Wendung.init()` once when your application starts, before any other SDK method. The `consent` and `trackPageviews` options determine whether collection starts. When collection is active, the SDK starts the auto-flush timer and registers `visibilitychange` and `pagehide` listeners to send queued events. Calling `init()` again tears down the previous instance first, so it is safe under React Strict Mode and Next.js Fast Refresh.

```typescript theme={null}
Wendung.init(config: InitConfig): void
```

## Parameters

<ParamField body="apiKey" type="string" required>
  Your publishable API key, safe to include in browser code. Sent with every request as the `X-API-Key` header. A missing or empty value makes `init()` throw.
</ParamField>

<ParamField body="endpoint" type="string" default="https://ingest.wendung.app/v1/events">
  Ingest URL. If you override it, it must use `https://`; plain `http://` is only allowed for `localhost`, `127.0.0.1`, or `[::1]`. An invalid or insecure URL makes `init()` throw synchronously.
</ParamField>

<ParamField body="flushInterval" type="number" default={5000}>
  Milliseconds between automatic flushes. The timer does not start on the server.
</ParamField>

<ParamField body="maxBatchSize" type="number" default={50}>
  Events per request. When the queue reaches this size, a flush is triggered immediately regardless of the timer. The effective value is clamped to 1–100; values above 100 log a one-time warning.
</ParamField>

<ParamField body="trackPageviews" type="boolean | 'auto'" default={false}>
  Automatic pageviews are off by default. `true` records full pageviews only with granted consent. `'auto'` records aggregate pageviews while consent is pending, then full pageviews after consent is granted. `denied` stops collection in either mode.

  When enabled, the SDK records the initial load and navigation through `pushState`, `replaceState`, and `popstate`. Aggregate collection ignores changes to only the query string or fragment. Pageviews count against your plan's pageview allowance and appear in reports for registered [sites](/help/sites). See [`page()`](/api-reference/page) for manual capture.
</ParamField>

<ParamField body="consent" type="'pending' | 'granted' | 'denied'" default="granted">
  The visitor's analytics choice at startup. `pending` allows only aggregate pageviews when `trackPageviews` is `'auto'`; otherwise it stops collection. `granted` enables full analytics. `denied` stops all collection, discards queued events, and removes stored SDK identifiers.

  Pass the saved choice on every load. The SDK does not store it. Use [`setConsent()`](/api-reference/set-consent) when the choice changes. See the [consent guide](/guides/consent) for the setup and data limits.
</ParamField>

<ParamField body="debug" type="boolean" default={false}>
  When `true`, the SDK emits `[Wendung]` log messages to the console. Warnings (`[Wendung - Warning]`) fire regardless of this setting. See [Debugging](/configuration/debugging).
</ParamField>

## Returns

`void`

## Examples

### Minimal setup

```typescript theme={null}
import { Wendung } from '@wendung/sdk'

Wendung.init({
  apiKey: 'pk_your_publishable_key',
})
```

### Script tag

On a site without a build step, the CDN build initializes itself from data attributes and exposes `Wendung` on `window`. See the [script tag guide](/guides/script-tag) for the attribute list.

```html theme={null}
<script
  defer
  src="https://cdn.wendung.app/sdk/latest/wendung.js"
  data-api-key="pk_your_publishable_key"
  data-track-pageviews
></script>
```

### Next.js App Router

See the [Next.js guide](/guides/nextjs) for the recommended `<WendungProvider>` pattern. A minimal version:

```tsx theme={null}
'use client'
import { useEffect } from 'react'
import { Wendung } from '@wendung/sdk'

export function WendungProvider({ children }: { children: React.ReactNode }) {
  useEffect(() => {
    Wendung.init({ apiKey: process.env.NEXT_PUBLIC_WENDUNG_KEY! })
    return () => Wendung.destroy()
  }, [])
  return <>{children}</>
}
```

<Note>
  `Wendung.init()` is browser-only. The package has no import-time side effects, but call `init()` and tracking methods from client-side code. Server runtimes skip the flush timer and page-lifecycle listeners; in runtimes with `fetch`, manual flushes can still attempt network requests.
</Note>


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