这是我在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`,
},
},不知道为什么它不工作,它甚至没有在我的源代码上显示任何谷歌分析。
提前谢谢。
发布于 2019-12-07 21:42:39
我也不能让它在生产中工作。我也尝试过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>..。但我还没有成功地在生产中测试它。我已经安装了所有的谷歌分析插件,虽然调试在头盔的情况下工作,但我没有真正得到良好的结果,否则。
发布于 2021-02-19 02:33:45
使用带有以下配置的gatsby-plugin-google-gtag来支持google analytics 4。把它放在插件列表的顶部,如果没有"anonymize_ip: true“,我就不能让它工作。
plugins: [
{
resolve: `gatsby-plugin-google-gtag`,
options: {
trackingIds: [
"GA-TRACKING_ID", // Google Analytics / GA
],
pluginConfig: {
head: true,
anonymize_ip: true,
},
},
},
// other plugins
],发布于 2020-05-10 20:06:58
对我来说,它不起作用,因为我使用的是广告拦截器浏览器插件,它阻止了所有的分析数据。禁用插件后,一切都运行得很好。
https://stackoverflow.com/questions/59050471
复制相似问题