Google Analytics Next.js 中未设置页面标题
Page title not set in Google Analytics with Next.js
我已经在 Next.js 中配置了我的 Google 分析,但我遇到了一个奇怪的问题,分析无法检测到我的网页,而是显示 (not set)
。看来其他一切正常。
我把脚本添加到_document.js
的<Head>
标签里面,检查了很多次,没有拼写错误。
有人知道会发生什么吗?
您的页面似乎没有直接在每个页面上显示 document title set. Setting the document title in Next.js can be achieved using next/head
。
// `/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>
</>
)
}
我已经在 Next.js 中配置了我的 Google 分析,但我遇到了一个奇怪的问题,分析无法检测到我的网页,而是显示 (not set)
。看来其他一切正常。
我把脚本添加到_document.js
的<Head>
标签里面,检查了很多次,没有拼写错误。
有人知道会发生什么吗?
您的页面似乎没有直接在每个页面上显示 document title set. Setting the document title in Next.js can be achieved using next/head
。
// `/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>
</>
)
}