How to add aydex.cloud analytics to a Next.js app

One component in your root layout is all a Next.js app needs.

Last updated

The aydex script tracks client-side navigations by itself, so no router hooks are needed. Load it with next/script in the root layout.

import Script from 'next/script'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script src="https://t.aydex.cloud/script.js" data-site="YOUR_TRACKING_ID" strategy="afterInteractive" />
      </body>
    </html>
  )
}

Custom events

After the script loads, call window.aydex.track('signup') anywhere in client code. Event names starting with an underscore are reserved.

Avoid ad blockers

Some blockers filter third-party analytics domains. You can proxy the script and collector through your own domain using Next.js rewrites; see the first-party proxy recipes in the aydex README.

Frequently asked questions

Does it work with the Pages Router?
Yes. Put the same Script component in pages/_app.tsx.

Try it on your own site

Free for up to 10,000 pageviews a month. One script tag, no cookies.

Start free