To measure your websites with Matomo (Piwik) you are likely to use the Matomo JavaScript Tracking code, a small snippet of code that should be added in your websites pages. When visitors view your website, the Matomo tracking code gets executed by the browser and your visitor’s browsers load the matomo.js file from your Matomo server, for example: demo.matomo.cloud/piwik.js.

In some cases it may be useful to customise the matomo.js tracking code. This FAQ explains the best practise method to let you safely edit the matomo.js file. Note that this is an advanced feature and should be used with great care. First you will need to install and activate the plugin JsTrackerCustom. Login as a Super User in Matomo then go to Administration, click on Marketplace and install the plugin JsTrackerCustom. After activating this plugin, Super User can click on the Admin menu ‘Plugin Settings’ link. Any text entered in the field ‘Javascript code’ will be appended to the content of matomo.js.

For example, if you wanted to enable Content Tracking on all your websites at once, enter the following:

if ('undefined' !== typeof _paq) {
     _paq.push(['trackVisibleContentImpressions']);
}

Note: changing matomo.js will affect all your websites at once (all websites load the same matomo.js file). Use this feature with care: if you input invalid JavaScript code then it may create JavaScript errors on your websites.

Previous FAQ: A search engine is counted as a website referrer. How can I add the search engine to Matomo?