Why we replaced Google Analytics with Matomo, and why you should too

Security software engineer
Why we replaced Google Analytics with Matomo, and why you should too

When you enabled Google Analytics (GA) on your website maybe you thought "I don't really have another viable option". Or maybe you thought "the negative effect on my visitors isn't that bad, is it?" Both are relatable, but recently Data Protection Authorities have put GA under a microscope and concluded it actually is pretty bad. Some things in GA violate the GDPR. Apart from the question of whether it is legal or not, the fact that your visitors are tracked across the internet - we feel - is just awful. And, as it turns out, you do have options.

So, a while back we decided to remove GA from our website and replace it with Matomo, an open-source, privacy-friendly alternative!

Why not do the same?

If you're convinced already, you can skip right away to section 4. But if you need a little extra push, here is a shortlist of reasons answering the question: Why should you stop using Google analytics?

1. Because people visiting your website should have a real choice.

This should be the main reason to stop using Google Analytics. Most people using the internet have no idea that many sites use Google Analytics to track them. The fact that these sites are using this data to improve the experience is probably of little concern to these people, but the fact that Google can now track them across all these sites, see their every click and sells this data to advertisers is a lot more worrying. As it is now, people cannot simply enjoy the internet without the option of being tracked, you could start by making your website a safe(r) place to be, by not using Google analytics.

2. Because the data you are collecting isn't yours.

Or is it? Is it your visitor's? Or Google's? Even though this might be hard to figure out, there is one thing that is certain: Google makes money from selling it. Most alternatives do not: they promise that they won't allow access to the collected data for external parties, and that it is 100% yours.

The best way to ensure that you have full access to the data is by choosing the self-hosted option. What this means is that you are running a version of the analytics software on one of your servers, thereby making sure that the data is not sent to any third party. Most open-source analytics software offer this option for free or paid, but also offers a cloud-based variant in which they do the hosting for you.

3. Because it might become illegal (in the EU) soon!

In my personal opinion, this is the last reason to stop using Google analytics, as I think doing it because you care is way more important than because you're forced by law. But since I want to close off with listing some alternatives, it is the second to last in this list of reasons.

The Austrian Data Protection Authorities have ruled that the use of Google Analytics (in one specific case) violates the GDPR regulations. The authorities ruled that, even though the anonymizeIP setting was enabled, this would only anonymize the IP address after it would be sent to Google and therefore sharing this personal data with the big search engine company. The Dutch Data Protection Authorities have recently also warned that this might become the case in the Netherlands (Dutch), to allow companies to prepare for change.

Even though I think this is going in a good direction (regulation-wise), I do have my doubts regarding the impact it is going to make. It sounds very plausible that Google will change a few lines of code to be compliant again. At the same time, a lot of web pages use reCaptcha or Google's CDN and continue to send their visitors' IP addresses to Mountain View, California *. As we are no lawyers at Tweede golf, we leave this argument to the experts in the field and only list our concerns regarding the actual technical implementation.

* Coincidentally, in the meantime a German Court ordered that embedding Google Fonts also violates the GDPR for the same reason.

4. Because there are plenty of good alternatives

There is no good reason not to stop using Google analytics; good alternatives are widely available, and switching is remarkably simple! We chose Matomo because the functionality is more or less the same as Google Analytics, but there are plenty of others out there. They might not offer the same functionality as Google Analytics does, but they do have one thing in common: they respect the privacy of your visitors (at least more than Google does). But first, to illustrate how easy it is to switch from Google analytics to Matomo, I included the diff of the code we needed to change:

if (window.location.host === 'tweedegolf.nl') {
-  const ga = window.ga = window.ga || function () {
-    (ga.q = ga.q || []).push(arguments);
-  };
-  ga.l = +new Date;
-  ga('set', 'anonymizeIp', true);
-  ga('create', 'UA-110163608-1', 'auto');
+  var _paq = window._paq = window._paq || [];
+  _paq.push(['setDoNotTrack', true]);
+  _paq.push(['enableLinkTracking']);
+  (function () {
+    _paq.push(['setTrackerUrl', 'https://tweedegolf.matomo.cloud/matomo.php']);
+    _paq.push(['setSiteId', '1']);
+  })();
-<script async src="https://www.google-analytics.com/analytics.js"></script>
+<script async src="https://cdn.matomo.cloud/tweedegolf.matomo.cloud/matomo.js"></script>

Since our website is a React single-page application, there are no refreshes when switching pages. Therefore, there are a few more lines in the router, but as you can see; not exactly Rocket science:

useEffect(() => {
  setTimeout(() => {
-    if (isProduction && window.ga) {
-      window.ga('send', 'pageview', route.path);
+    if (isProduction && window._paq) {
+      window._paq.push(['setCustomUrl', route.path]);
+      window._paq.push(['setDocumentTitle', window.document.title]);
+      window._paq.push(['trackPageView']);
  }, 1);
}, [route?.path]);

Code-wise, that's all there is to do! You are now ready to give your visitors a carefree experience on your webpage. Have a look at the great dashboard you get:

Matomo dashboard

When you've already been using Google analytics for a long time, you might want to take this data with you. Luckily, Matomo also provides a walkthrough for this. If you are not yet convinced, have a look at what some of the alternatives have to say themselves:

  • Matomo (previously Piwik) is open source and has a self-hosted and a (European) cloud-based variant.
  • Plausible is simpler than Matomo, also open source and has a free self-hosted and a paid (European) cloud-based variant.
  • Simple Analytics is closed source and only has a cloud-based variant, but it is hosted in the Netherlands!
  • And many more...

What we didn't cover in this post is a comparison in functionality. We didn't do this because we only use a fraction of the functionality and therefore we don't consider ourselves experts on this side of the story. Besides that, it greatly depends on your own needs and preferences. If you do have some specific functionality you absolutely need, the alternatives we listed all have a side-by-side comparison of the functionality! Here's the one from Matomo: https://matomo.org/matomo-vs-google-analytics-comparison/

It is clear that there are plenty of reasons not to use Google Analytics, but we also know that there are things we didn't cover. If you are into law, an expert in analytics, or have something else to add, feel free to contact us or leave a comment on the platform where you found this post and we'll get back to you.

Stay up-to-date

Stay up-to-date with our work and blog posts?

Related articles

The number of data centers worldwide is constantly increasing, and so is their electricity consumption. One way to become more power-efficient is certainly the constant development of better hardware, but we as developers should do our share. This post shows how coding in Rust can help to use existing resources more efficiently, to help preserve our planet — at least a little bit.
Asynchronous programming is pretty weird. While it is straightforward enough to understand in principle (write code that looks synchronous, but may be run concurrently yada yada yada), it is not so obvious how and when async functions actually perform work. This blog aims to shed light on how that works in Rust.
Just because we're engineers, doesn´t mean we build ALL our applications ourselves. But sometimes inspiration hits and good things happen. So our company planner is now canvas-rendered, has a Rust backend and works like a charm.