Add DataFast to your Next.js App Router project
Follow these steps to integrate DataFast analytics into your Next.js application using the App Router (v13+).
Add tracking script to Root Layout
The recommended way to add scripts to all pages in a Next.js App Router application is by using the root layout file.
-
Open your project's root layout file, typically located at
app/layout.jsx
. -
Import the
Script
component fromnext/script
. -
Add the DataFast tracking script to the
<head>
section of your layout component.Here's an example for
app/layout.jsx
:import Script from "next/script"; export default function RootLayout({ children }) { return ( <html lang="en"> <head> <Script data-website-id="YOUR_WEBSITE_ID" data-domain="YOUR_DOMAIN.COM" src="https://datafa.st/js/script.js" strategy="afterInteractive" /> </head> <body>{children}</body> </html> ); }
Replace
YOUR_WEBSITE_ID
with your actual Website ID from DataFast. ReplaceYOUR_DOMAIN.COM
with your website's root domain. -
Save the file, commit and deploy your changes.
DataFast is disabled on localhost to avoid tracking your own traffic.
Verify installation
After deploying your changes:
- Visit your live website.
- Check your DataFast dashboard for incoming data. It might take a few minutes for the first pageviews to appear.