Google analytics 让谷歌分析与鹈鹕合作

Google analytics 让谷歌分析与鹈鹕合作,google-analytics,pelican,Google Analytics,Pelican,所以我最近开始在Pelican上写博客,除了Google Analytics,一切都很顺利。我使用 make s3_upload 命令,该命令使用publishconf.py文件 为了获取我的跟踪ID,我所做的只是将我的跟踪ID从google analytics页面复制粘贴到publishconf.py文件中的google analytics行中,如下所示 # Following items are often useful when publishing #DISQUS_SITENAME

所以我最近开始在Pelican上写博客,除了Google Analytics,一切都很顺利。我使用

make s3_upload
命令,该命令使用publishconf.py文件

为了获取我的跟踪ID,我所做的只是将我的跟踪ID从google analytics页面复制粘贴到publishconf.py文件中的google analytics行中,如下所示

# Following items are often useful when publishing

#DISQUS_SITENAME = ""
GOOGLE_ANALYTICS = "UA-########-#"

任何帮助都将不胜感激,我一直在绞尽脑汁试图解决这个问题

解决方案

  • 编辑publishconf.py

    GOOGLE#u ANALYTICS=“UA-######-#”

  • 建立网站

    鹈鹕内容物

  • 根据设置修改网站=添加谷歌分析

    鹈鹕-s publishconf.py

  • 部署

    cd输出和git推送原始主机(&G)

  • 测试步骤是否有效:

  • 在output/index.html的末尾添加了以下内容:

    <script type="text/javascript">
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-125105451-1', 'auto');
    ga('send', 'pageview');
    </script>
    
    
    (函数(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]| |函数(){
    (i[r].q=i[r].q | |[]).push(参数)},i[r].l=1*新日期();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(窗口、文档、“脚本”和https://www.google-analytics.com/analytics.js","ga",;
    ga(“创建”、“UA-125105451-1”、“自动”);
    ga(‘发送’、‘页面浏览’);
    
  • 检查javascript代码是否已添加到github repo中。检查代码是否在“专用导航”中提供(以禁用浏览器缓存)。右键单击网页>查看来源

  • 上下文:部署到github页面

    博客的Git:

    cd output/ 
    git init .
    git remote add origin git@github.com:<username>/<username>.github.io.git
    # Deploy with:
    # git add . && git commit -m "Commit description" && git push origin master
    
    cd输出/
    git init。
    git远程添加源git@github.com:/.github.io.git
    #部署时使用:
    #吉特增补,git提交-m“提交描述”&&git推送源主机
    
    博客引擎的Git:

    cd output && cd .. # ensure to be in the good repository
    git init .
    git submodule add git@github.com:<username>/<username>.github.io.git output/
    
    cd输出和&cd确保在良好的存储库中
    git init。
    git子模块添加git@github.com:/.github.io.git输出/
    
    如果站点的输出中没有分析片段,则可能是您使用的主题没有包含正确的代码

    每个主题都应该有一个
    base.html
    文件,您应该查看该文件以确保它包含在其中。如果没有,您可以添加以下内容:

    {%if GOOGLE_ANALYTICS%}
    window.dataLayer=window.dataLayer | |[];
    函数gtag(){dataLayer.push(参数);}
    gtag('js',新日期());
    gtag('config','{{GOOGLE_ANALYTICS}}}');
    {%endif%}
    
    您能否确认Pelican呈现的HTML中存在Google Analytics跟踪片段?就是这样,它不在任何创建的输出中。我查看了模板,里面也没有任何内容。正如我所看到的,有两个选项可以将其添加到主题中,或者切换主题。谢谢你的帮助!我知道这很愚蠢,我也有同样的问题。我定义了
    GOOGLE\u ANALYTICS
    变量,但我的输出中缺少该代码段。也许他们已经解决了。对我来说,这只不过是增加了
    GOOGLE\u分析的价值