【问题标题】:My Google Analytics setup for hugo is not working我的雨果谷歌分析设置不工作
【发布时间】:2021-05-28 12:00:57
【问题描述】:

我已将我的跟踪 ID 添加到我的 config.toml 中,并且一切看起来都匹配。然而,当我启动https://analytics.google.com/时,我还没有看到任何实时数据进入

theme = "osprey-delight"
tags = ["personal", "homepage", "portfolio"]
# canonifyURLS = true
googleAnalytics = "G-SYJ123456"
disableKinds = ["taxonomy", "taxonomyTerm"] # This theme does not currently use "tag" and "category" taxonomies
enableEmoji = true
pygmentsUseClasses = true

我正在使用主题(osprey-delight),在 layouts/partials 目录中,有一个包含模板字符串的 head.html,将粘贴在下面:

  {{ if .Site.GoogleAnalytics }}
    {{ template "_internal/google_analytics_async.html" . }}
  {{ end }}

当我部署到 firebase 时,我确实在 /public 目录中的主 index.html 文件中看到了 ga 的脚本标签,它在下面 -

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'G-12345689', 'auto');
    
    ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

我错过了什么?我觉得我没有做对所有事情,但还没有运气。

【问题讨论】:

    标签: google-analytics firebase-hosting hugo google-analytics-4


    【解决方案1】:

    2020 年 2 月更新

    您可以在下面找到 Universal Analytics 的解决方案,或者您可以尝试实施 Hugo 的解决方案以将数据发送到您的 GA4 数据流:https://gist.github.com/zjeaton/42246742cdaf2fb46400d04c2eba9a8a#file-analytics-gtag-html


    Universal Analytics 解决方案

    我建议您创建一个 Universal Analytics Property(如下图所示)并使用相对标识符 UA-XXXXXXX-X(简单方法):

    或者,如果您想使用 GA4 属性,您必须遵循相关语法: https://developers.google.com/analytics/devguides/collection/ga4

    【讨论】:

    • 所以我要在我的配置文件中添加 UA 密钥?
    • 您是否必须在属性设置期间选择此选项,或者您可以在事后添加此选项?我在属性设置中没有看到它。
    • 新建属性时可以找到
    【解决方案2】:

    您可以按照 Zachary Eaton 的建议实施 Hugo 解决方案,并保留您的 GA4 媒体资源:https://gist.github.com/zjeaton/42246742cdaf2fb46400d04c2eba9a8a#file-analytics-gtag-html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      相关资源
      最近更新 更多