Modifying Tracking Code


I’m using Piwik 3.0.3 and am attempting to modify my tracking code to add download extensions, like such:

_paq.push([‘addDownloadExtensions’, “pkg|msi|spk|bin”]);

I’ve read that I need to use CustomTrackerJs plugin but that doesn’t seem compatible with 3.0.3, or at least there’s no obvious way for me to use it (checked Plugin Settings).

Alternatively, is it safe for me to manually edit my piwik.js file server-side?

If anyone can offer help I would be very grateful.


  • Joseph

For reference, this is the set of instructions I’ve attempted to follow: How do I customise the JavaScript Tracker code on all websites at once? - Analytics Platform - Piwik

I think you have misunderstood something. You’ll newer need to modify piwik.js (except when you are a writing a plugin).

This line needs to be added to the tracking code which you have added to your website and should look like this

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  (function() {
    var u="//{$PIWIK_URL}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
<!-- End Piwik Code -->

(Ideally before the line _paq.push(['trackPageView']);)

hi lukas,
I have the same query as above.
I am writing a function in piwik.js and on the click of a button on my website I call that function.
That function is working.
BUT-> The piwik.js removes that function after a certain period (30 minutes approx) automatically.
I too have installed customtrackerjs plugin which is not comaptible.
Help will be much appreciated.


In that case check what I have written here:


Small note: Keep in mind that the piwik.js is loaded asynchronously, which means it isn’t guaranteed that the function has already been loaded when the user clicks on the button.

When you call _paq.push([‘addDownloadExtensions’, “pkg|msi|spk|bin”]); from your code it works the same before and after Matomo was initialized.

will work on it.