> For the complete documentation index, see [llms.txt](https://userlens.gitbook.io/userlens-analytics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://userlens.gitbook.io/userlens-analytics/getting-started/nextjs.md).

# Next.js

Integrate the Userlens SDK into your Next.js application, with proper handling for server-side rendering.

## Installation

```bash
npm install userlens-analytics-sdk
```

## Choose Your Setup

|                     | Client-Side Setup | Proxy Setup                        |
| ------------------- | ----------------- | ---------------------------------- |
| **Best for**        | Most applications | Apps needing ad blocker resistance |
| **Backend changes** | None              | Uses Next.js API routes            |
| **Setup time**      | \~5 minutes       | \~15 minutes                       |

{% content-ref url="/pages/KiX5rIopkDagFr6a3wis" %}
[Client-Side Setup](/userlens-analytics/getting-started/nextjs/client-side.md)
{% endcontent-ref %}

Events go directly from the browser to Userlens. Quick to set up, no API routes needed.

{% content-ref url="/pages/xNqR8M2VqGLmpUsPSCga" %}
[Proxy Setup](/userlens-analytics/getting-started/nextjs/proxy.md)
{% endcontent-ref %}

Events flow through your Next.js API route first. Use this if you need to avoid ad blockers.
