Note: This post is from an old Pelican blog I used to have at simonh.me, which I found on a backup drive on 2025-01-07. It's probably of no use, but reposted for posterity!

I thought I'd put this on here in case anyone else had the same problem. By the way, some of the code samples below have been reformated so will look different to the linked files.

The Problem

I'm using this theme for my son's website: https://github.com/getpelican/pelican-themes/tree/master/bricks. He likes it a lot and it seemed to tick all the right boxes.

  1. It actually works. Many of the themes I tried on pelican-themes didn't work.

  2. It's responsive. Pretty much mandatory especially considering when his friends visit his site, they'll be on their phone.

  3. It looks nice. Again, quite important, especially as their aren't many themes (that I could find) which are suited to a childrens site.

  4. It supports Google Analytics. Well, I thought it did.

In the file templates/analytics.html from the above repo, there is this code:

{% if GOOGLE_ANALYTICS %}
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
        var pageTracker = _gat._getTracker("{{GOOGLE_ANALYTICS}}");
pageTracker._trackPageview();
} catch(err) {}</script>
{% endif %}

I checked in templates/base.html (which all other pages inherit from, I believe) but there was no mention of Google Analytics. Below is the very bottom of base.html:

</div>
        </row>
        {% endblock %}
        </div>
        {% include 'trademark.html' %}
</div>
</body>
</html>

I thought that may be the problem. So, I checked the theme I'm using for this site https://github.com/duilio/pelican-octopress-theme.

At the bottom of templates/base.html we have this:

</div>
</div>
<footer role="contentinfo">{% include '_includes/footer.html' %}</footer>
        <script src="{{ SITEURL }}/theme/js/modernizr-2.0.js"></script>
        <script src="{{ SITEURL }}/theme/js/ender.js"></script>
        <script src="{{ SITEURL }}/theme/js/octopress.js" type="text/javascript"></script>
        {% include '_includes/after_footer.html' %}
</body>
</html>

I then checked in _includes/after_footer.html which contains this:

{% include '_includes/analytics.html' %}
{% include '_includes/piwik.html' %}
{% include '_includes/disqus_script.html' %}
{% include '_includes/twitter_sharing.html' %}
{% include '_includes/google_plus_one.html' %}
{% include '_includes/facebook_like.html' %}
{% include '_includes/isso_script.html' %}

That seemed to be what the bricks theme was missing. I altered base.html to this:

</div>
</row>
{% endblock %}
</div>
        {% include 'trademark.html' %}
</div>
        {% include 'after_footer.html' %}
</body>
</html>

created the file after_footer.html with this line in:

{% include 'analytics.html' %}

Copied the contents of analytics.html from the octopress theme to the bricks theme, and we're done!

This should work with other themes as well. I plan on becoming better acquainted with Jinja2 and create or modify some themes for other projects so check back every now and then.