@anonymous-matomo-user opened this Issue on August 23rd 2010

It seems like there's no way to hook in custom javascript/file through the tracker (piwik.js) code. This is required by third-party plugins to gather more information from client-side environment in addition to that provided by Piwik's own tracker. There exist hooks in piwik.js, but I think there's no way to utilize them without injecting/modifying the default tracker script/code/tags.

I am working on a HeatMap/ClickMap plugin for Piwik (from scratch, not based off the well-known ClickHeat plugin). In order to track client side events, I must make additions to the tracker script or hook it somehow into the tracker so that my script/code is executed. Using a separate JavaScript tag, in addition to piwik.js, does the job:

<script type="text/javascript"> 
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.******.com/" : "http://piwik.******.com/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "js/piwik.js' type='text/javascript'%3E%3C/script%3E"));
document.write(unescape("%3Cscript src='" + pkBaseURL + "plugins/HeatMap/heatmap.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript"> 
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", *);
} catch( err ) {};

But, I am actually looking forward to a seamless integration mechanism where users won't have to modify existing Piwik tracking tags. Ideally Piwik tracker code would pull the plugin code. This may be possible by dynamically generating (and caching) piwik.js and including blocks of codes pre-registered by third-party plugins, right within piwik.js.

@robocoder commented on August 23rd 2010 Contributor

Hooks in piwik.js was implemented to facilitate unit testing. This will be reworked in #739.

With the AssetManager and changes in #1527, we'll be a step closer to dynamically generating a kitchen-sink version of piwik.js (i.e., that includes third-party plugin-specific JavaScript).


  • Since we have to maintain backward compatibility (i.e., serving the static file, piwik.js), the URL would have to be different, so the default tracking code is unavoidable.
  • There are cases where it's desirable for only specific plugin functionality to be enabled/disabled on a page. That implies having some fine-grained control on which plugin's JavaScript is either loaded or executed. Perhaps something like:
document.write(unescape("%3Cscript src='" + pkBaseURL + "index.php?module=CoreHome&action=getTracker&plugins=PluginA+PluginC+PluginG' type='text/javascript'%3E%3C/script%3E"));
  • we also have to look into asynchronous tracking code

Rolling into #739 by reference.

This Issue was closed on August 23rd 2010
Powered by GitHub Issue Mirror