【问题标题】:Page title not set in Google Analytics with Next.js未在 Google Analytics 中使用 Next.js 设置页面标题
【发布时间】:2020-12-29 15:29:05
【问题描述】:
我已经在 Next.js 中配置了我的 Google Analytics,但我遇到了一个奇怪的问题,即分析无法检测到我的网页,而是显示 (not set)。似乎其他一切都正常。
我在_document.js的<Head>标签内添加了脚本,并多次检查拼写没有错误。
有人知道会发生什么吗?
【问题讨论】:
标签:
javascript
google-analytics
next.js
【解决方案1】:
您的网页似乎没有设置document title。在Next.js中设置文档标题可以在每个页面直接使用next/head实现。
// Let's assume this is a page under `/pages/index.js`
import Head from 'next/head'
function IndexPage() {
return (
<div>
<Head>
<title>Index page title</title>
</Head>
<p>Index page content</p>
</div>
)
}
export default IndexPage