sakana

very short memo

google anlytics in sphinx

If you would like to analyze statics of access to your site built with sphinx, then you can embed google analytics code in it.

Prepare layout.html file under source/_templates directory. Insert javascript code obtained at google analytics site.

{% extends "!layout.html" %}

{% block footer %}
{{ super() }}
<div class="footer">
<script>
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxxx-x', '<site_name>');
ga('send', 'pageview');
</script>
</div>
{% endblock %}

And rebuild html and deploy it onto site.

For details, please refer to sphinx FAQ.