这是我在 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`,
},
},
不知道为什么它不起作用,它甚至没有在我的源代码上显示任何谷歌分析。
提前致谢。
最佳答案
我也不能让它在生产中工作。我也试过 https://www.gatsbyjs.org/packages/gatsby-plugin-gtag/ - 我听说这是“更新”的方式,我可以像这样使用 Helmet 得到一些结果:
<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>
...但我还没有在生产中成功测试。我已经安装了所有的 google 分析插件,虽然调试在 Helmet 的情况下有效,否则我并没有真正得到好的结果。
关于google-analytics - “gatsby-plugin-google-analytics”不适用于我的 gatsby-strapi 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59050471/