Installation

Install Visitors on Next.js

For this guide, we will strictly be referring to Next.js App Router (v13+).

Replace YOUR_TOKEN with your project token.

Using the root Layout

When it comes to Next.js, the recommended way to add scripts to a project is using the root Layout file.

Layout.tsx
import Script from 'next/script'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <head>
        <Script 
          src="https://cdn.visitors.now/v.js" 
          data-token="YOUR_TOKEN"
        />
      </head>
      <body>{children}</body>
    </html>
  )
}