Reputation: 371
I have configured my Google Analytics in Next.js but I am having this weird problem that analytics is unable to detect my webpages, instead it shows (not set)
. It seems that everything else is working alright.
I have added the script inside the <Head>
tag of _document.js
and checked many times that there wasn't any error in spelling.
Does anybody have an idea of what can be happening?
Upvotes: 1
Views: 2188
Reputation: 2040
Version Nextjs 13.2 onwards
Nextjs 13 has introduced Built-in SEO support with new Metadata API. If your page title is static, define a const 'metadata' in your Page.tsx file.
export const metadata = {
title: "Your Page Title",
};
Ref: https://nextjs.org/blog/next-13-2#built-in-seo-support-with-new-metadata-api
Upvotes: 0
Reputation: 50458
It looks like your pages do not have a document title set. Setting the document title in Next.js can be achieved using next/head
directly on each page.
// `/pages/index.js`
import Head from 'next/head'
export default function IndexPage() {
return (
<>
<Head>
<title>Index page title</title>
</Head>
<div>
<p>Index page content</p>
</div>
</>
)
}
Upvotes: 2