I have a custom tracking JavaScript file that tags certain DOM elements’ clicks and records them via the piwikTracker function call.

The problem is that the WP scripts are loaded in the header and the piwik script is apparently loaded in the footer.

I specified that my JavaScript wait for the ready handler but my script still does not load when I enqueue the script with a dependency on the script ‘wp-piwik’.

If I remove the dependency then I get this error in Chrome.

So am I even loading piwik? How do I load the tracking script on each page (I though it was by default)? and what is the alias of the script so I can specify the dependency?

If the piwik tracking script is not being loaded, would I have to copy and paste Piwik’s tracking code into it’s own script and load that like I would any other JavaScript file? I figured the plugin handled that for me:

I actually solved the issue by loading the custom tracking scripts in my own plugin instead of functions.php.

I’m not sure if the default priority settings were in play or not (I left them to default) but it seemed to solve the issue. Perhaps loading any custom tracking in functions.php that calls for piwikTracker.js is loaded before Piwik, despite my javascript calling the functions only when the page is in ready state.