Prerequisites
- tinytrack websiteId
- Nextjs 14+
Install
1
Install tinytrack package
2
Add the proxy
Create
proxy.ts at the root of src/:Next.js 14+: use middleware.ts
Next.js 14+: use middleware.ts
Use
middleware.ts at the root of src/ with a middleware export instead:Already have middleware or a proxy?
Already have middleware or a proxy?
Rename your existing handler to For
appMiddleware and wrap it using the named import: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.Pages Router only: also add this
App Router
Add the tracker inside your existing server layout’s<body>:Pages Router
Add the tracker alongside your page component:Optional: environment variable
OmitwebsiteId from both the middleware and tracker, and set this in .env.local and your hosting environment before building:env entry to your Next.js config so the tracker can read the ID in the browser: