Google analytics ';盖茨比插件谷歌分析';不是为我的盖茨比·斯特拉皮网站工作

Google analytics ';盖茨比插件谷歌分析';不是为我的盖茨比·斯特拉皮网站工作,google-analytics,gatsby,Google Analytics,Gatsby,这是我在gatsby-config.js中的代码 module.exports = { siteMetadata: { title: `title`, description: ``, author: `@Wavii`, }, plugins: [ { resolve: `gatsby-plugin-google-analytics`, options: { trackingId: "UA-XXXXXX-XX"

这是我在gatsby-config.js中的代码

module.exports = {
  siteMetadata: {
    title: `title`,
    description: ``,
    author: `@Wavii`,
  },

  plugins: [
    {
      resolve: `gatsby-plugin-google-analytics`,
      options: {
        trackingId: "UA-XXXXXX-XX",
        // Defines where to place the tracking script - `true` in the head and `false` in the body
        head: true,
      },
    },
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
不知道为什么它不起作用,它甚至没有在我的源代码上显示任何谷歌分析


提前谢谢。

我也不能让它在生产中工作。我也尝试过——我听说这是一种“更新”的方法,我可以像这样使用头盔获得一些结果:

  <Helmet>
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXX-X"></script>
  <script type="application/ld+json">{`
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('config', 'UA-XXX-X');
  `}</script>
  </Helmet>

{`
window.dataLayer=window.dataLayer | |[];
函数gtag(){dataLayer.push(参数);}
gtag(“配置”、“UA-XXX-X”);
`}

。。。但我还没有在生产中成功测试它。我已经安装了所有google analytics插件,虽然debug可以在头盔上运行,但在其他情况下我并没有得到很好的结果。

对我来说,它不起作用,因为我使用的是ad blocker浏览器插件,它阻止了所有分析数据。禁用插件后,一切都很顺利。

盖茨比插件google analytics生成过时的“ga”

切换到“盖茨比插件google gtag”即生成“gtag”

参考文献

与以下配置一起使用google analytics 4支持。 把它放在插件列表的顶端,如果没有“anonymize_ip:true”,我就无法让它工作


你是怎么测试的?请注意,该插件仅适用于生产版本
$gatsby build
plugins: [
    {
      resolve: `gatsby-plugin-google-gtag`,
      options: {
        trackingIds: [
          "GA-TRACKING_ID", // Google Analytics / GA
        ],
        pluginConfig: {
          head: true,
          anonymize_ip: true,
        },
      },
    },
    // other plugins
  ],