Skip to main content
Prerequisites

Install

1

Install tinytrack package

2

Add the proxy

Create proxy.ts at the root of src/:
Use middleware.ts at the root of src/ with a middleware export instead:
Rename your existing handler to appMiddleware and wrap it using the named import:
For proxy.ts, export proxy instead. Keep your existing matcher entries and add /_tinytrack/:path*.
3

Add the tracker

Choose your router and add the component once.

App Router

Add the tracker inside your existing server layout’s <body>:

Pages Router

Add the tracker alongside your page component:

Optional: environment variable

Omit websiteId from both the middleware and tracker, and set this in .env.local and your hosting environment before building:
Pages Router only: also add this env entry to your Next.js config so the tracker can read the ID in the browser: