使用 Pelican 使用 Google 分析

zni*_*sen 5 google-analytics pelican

所以我最近开始用 Pelican 写博客,除了谷歌分析之外,一切都很顺利。我发布我的博客使用

make s3_upload
Run Code Online (Sandbox Code Playgroud)

命令,它使用 publishconf.py 文件。

为了获得我的跟踪 ID,我所做的就是将我的跟踪 ID 从谷歌分析页面复制粘贴到 publishconf.py 文件中的谷歌分析行中,就像这样

# Following items are often useful when publishing

#DISQUS_SITENAME = ""
GOOGLE_ANALYTICS = "UA-########-#"
Run Code Online (Sandbox Code Playgroud)

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

Jef*_*eff 2

解决方案

  1. 编辑publishconf.py

    GOOGLE_ANALYTICS =“UA-########-#”

  2. 建设网站

    鹈鹕内容

  3. 根据设置修改网站=添加google Analytics

    鹈鹕-spublishconf.py。

  4. 部署

    cd 输出 && git push origin master

测试这些步骤是否有效:

  1. 在本地的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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 检查 javascript 代码是否已添加到您的 github 存储库中。检查代码是否在“私人导航”中提供(以便禁用浏览器缓存)。右键单击您的网页 > 查看源代码。

上下文:部署到 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
Run Code Online (Sandbox Code Playgroud)

博客引擎的 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/
Run Code Online (Sandbox Code Playgroud)