NextJS

Here are the steps for users to add your web analytics script to their Next.js project :

Steps to Add Script to a Next.js Project

  1. Go to your SiteBehaviour Organisation's page and click on the Settings button for your site.

  2. Go to the Tracking code tab.

  3. Click on Copy to copy the Tracking Code to your clipboard.

  4. In your Next.js project directory, find the pages folder. This folder contains the main entry point for your application, such as _app.js or _app.tsx.

  5. Open the _app.js (or _app.tsx if you're using TypeScript) file in the pages folder.

  6. At the top of your _app.js or _app.tsx file, import the Head component from next/head.

import Head from 'next/head';

7 . Add the Head component to your custom App component and place your SiteBehaviour script inside it.

// _app.js
import Head from 'next/head';
import '../styles/globals.css';

function MyApp({ Component, pageProps }) {
    return (
        <>
            <Head>
                <script>
                    {`
                        // Your sitebehaviour tracking script here
                    `}
                </script>
            </Head>
            <Component {...pageProps} />
        </>
    );
}

export default MyApp;

Last updated