Install TayStack on Next.js
Add the TayStack script to a Next.js site with the App Router or the Pages Router, then check in the dashboard that events arrive.
Not tested: Not yet tested on a live Next.js site. The steps follow how the platform is documented to work. Menu names change, so look for the setting described rather than the exact words.
Load the script with the Script component that comes with Next.js, once, in the part of your app that stays on screen between pages.
Replace site_xxxxxxxx and your-domain.com with your own site id and domain. The dashboard's Install card shows the tag with your values filled in.
App Router
Add the script to the root layout, so it loads on every page.
// app/layout.tsx
import Script from 'next/script'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
defer
data-website-id="site_xxxxxxxx"
data-domain="your-domain.com"
src="https://www.taystack.com/js/script.js"
/>
</body>
</html>
)
}Pages Router
Add the script to the custom App component, so it loads on every page.
// pages/_app.tsx
import type { AppProps } from 'next/app'
import Script from 'next/script'
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
<Script
defer
data-website-id="site_xxxxxxxx"
data-domain="your-domain.com"
src="https://www.taystack.com/js/script.js"
/>
</>
)
}Check it works
- Publish or deploy the change, then open your site on its real domain. Test addresses and editor previews may not match the domain you registered, and
localhostis not tracked. - Sign in, open your site in the dashboard and look at the Installation status. It reads “Waiting for the first event” until an event arrives, then “Receiving data”. It checks every few seconds while the page is open; the Verify installation button checks straight away.
- Click through two or three pages of your site, then look at the dashboard again. Route changes are recorded without extra code, see Single-page apps.
To look at the request itself, follow the steps in Quick start.
If it does not work
localhostis not tracked, sonext devsends nothing. Test on a deployed build.- Ad blockers: some block analytics scripts and the script fails silently. Test in a private window with extensions off. See Troubleshooting.
- Content Security Policy: if your site sends a
Content-Security-Policyheader,script-srcmust allowwww.taystack.comandconnect-srcmust allow it too, because events are sent there. - Caching: a page cache or CDN may still serve the old HTML without the script. Clear the cache, then reload.
- Both
data-website-idanddata-domainmust be present and match your site, or the script does nothing. More in Troubleshooting.
Back to all install guides.