When you track your website with Piwik or any other analytics solution, you need to embed a JavaScript file in order to track page views, events, clicks, and more. At InnoCraft, it is our daily business to help Piwik users to make the most out of their Piwik. We often see similar problems of websites loading unnecessarily slower because the tracking file is not loaded as fast as it should be. There are many ways you can improve the performance but avoiding the most important mistakes will help you to not lose revenue and conversions because of this today. Below you find a few steps that will boost the loading of your Piwik JavaScript tracking file.

Cache piwik.js

The most important step is to make sure to configure your server in a way so the piwik.js JavaScript tracker file will be cached once it has been loaded and not requested again on subsequent page views. Learn more about browser caching.

Enable GZIP

We recommend enabling GZIP as it reduces the size the user needs to load when the piwik.js file is requested. For the standard Piwik tracker, this will reduce the size from about 60KB to 20KB.

Preload DNS

Often a Piwik is hosted on a different domain and when the browser loads the JavaScript tracker file, it needs to first perform a DNS lookup to find the IP address for this domain. By adding the below snipped for your Piwik domain, it can boost the performance of loading the tracker file by 10ms to 50ms.

<link rel="dns-prefetch" href="//example.innocraft.cloud">

Preload resource

To boost the loading of the Piwik tracking file, you can add the following HTML into the header of your website:

<link rel="preload" href="https://yourpiwikdomain.com/piwik.js" onload="embedTracker()" type="script" crossorigin>

In Chrome, Opera, and soon in more browsers this will load the JavaScript tracker file without blocking the “onload” event. As a result, as soon as you embed the tracking code, the JavaScript tracker might be already loaded. How “preloading” affects your website always depends and maybe you rather want to preload more important resources than the tracking code, but it is an option to consider. If you load your JavaScript tracker file in the <head> of your website, this should not be needed.

Advanced options

If you want to go even further, you can think about serving the JavaScript tracking file via a CDN, merging the JavaScript tracker file content with your other JavaScript files, making use of service workers (and even track data offline), and more. Feel free to get in touch with us if you have any questions.

More performance improvements

Read our first blog in the series at Different ways of embedding the Piwik tracking code for faster website performance


InnoCraft

We are the makers of Piwik Analytics, the leading open source analytics platform used on more than 1 million websites and apps. We provide outstanding products and services to help you grow and achieve your business goals using the power of Piwik Analytics. We also love privacy and giving our customers full control over their digital analytics data.


Any questions?

Many answers and more information about Piwik You can find here:

We are social

Follow us: