【问题标题】: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

【讨论】:

  • 非常感谢!那肯定会成功的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 2011-03-28
  • 1970-01-01
相关资源
最近更新 更多