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.
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.
Solution
editing publishconf.py
GOOGLE_ANALYTICS = "UA-########-#"
Building the website
pelican content
Modifying the website according to settings = adding google analytics
pelican -s publishconf.py .
Deploying
cd output && git push origin master
Tests that the steps work:
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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With