Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Google analytics working with Pelican

Tags:

So I recently started blogging with Pelican, and everything is going great with the exception of Google Analytics. I publish my blog using the

make s3_upload

command, which uses the publishconf.py file.

To get my Tracking ID, all I did was copy paste my Tracking ID from the google analytics page into the Google Analytics line in the publishconf.py file, like so

# Following items are often useful when publishing

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

Any help would be greatly appreciated, I have been racking my brain trying to solve the problem.

like image 335
znielsen Avatar asked Feb 09 '17 06:02

znielsen


People also ask

Does Google Analytics work on Github pages?

Within a few hours Google Analytics should pick up the change, and you'll be capturing session times, demographics, and other useful information on visitors to your site.


1 Answers

Solution

  1. editing publishconf.py

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

  2. Building the website

    pelican content

  3. Modifying the website according to settings = adding google analytics

    pelican -s publishconf.py .

  4. Deploying

    cd output && git push origin master

Tests that the steps work:

  1. Locally at the end of output/index.html it added:

    <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>
    
  2. Check that the javascript code has been addded to your github repo. Check that the code is serve in a " private navigation " ( in order to disable browser caching). Right click on your webpage > see source.

Context: Deployment to github pages

Git for the blog:

cd output/ 
git init .
git remote add origin [email protected]:<username>/<username>.github.io.git
# Deploy with:
# git add . && git commit -m "Commit description" && git push origin master

Git for the blog engine:

cd output && cd .. # ensure to be in the good repository
git init .
git submodule add [email protected]:<username>/<username>.github.io.git output/
like image 105
Jeff Avatar answered Sep 25 '22 10:09

Jeff