Matomo Analytics with WagtailCMS

March 31, 2021

This guide will walk through integrating Matomo into your WagtailCMS website for a more private and secure method of tracking the number of visitors and other valuable metrics.

Introduction

Matomo is an open source alternative to Google Analytics that focuses on data ownership and privacy. Both a Cloud and an On-Premise solution exist. I opted for deploying Matomo to my own VPS. HowToForge has a great guide to help you deploy Matomo to your own server. https://www.howtoforge.com/how-to-install-matomo-piwik-on-centos-8/

WagtailCMS is an Open Source Content Management System built using Python and Django. This guide assumes that you have a website already built using Wagtail and you’re either ready to deploy or have already deployed into production.

Requirements

Configuring Wagtail

Let’s start by first configuring your Wagtail site for using the Matomo Javascript code. Matomo instructions say to add their Javascript to the <head> tag of your site and to ensure the code is in all webpages. I try to avoid inline CSS/Javascript code when possible.

Adding a new website to Matomo

If you’re using a freshly installed instance of Matomo you will have created a website during the first time setup process. Just follow the instructions and you’ll be provided with the Javascript code to add into your Wagtail site. Otherwise follow the instructions below.

Last Step

That’s it!

Restart your HTTP server, in my case both Gunicorn and Nginx. Make sure that tracking is allowed in your browser for your website. You should see hits in Matomo when your site is visited.

Cheers!

Return to blog index