Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking in JavaScript code from Plugin #1635

Closed
anonymous-matomo-user opened this issue Aug 23, 2010 · 1 comment
Closed

Hooking in JavaScript code from Plugin #1635

anonymous-matomo-user opened this issue Aug 23, 2010 · 1 comment
Labels
duplicate For issues that already existed in our issue tracker and were reported previously. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@anonymous-matomo-user
Copy link

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", *);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {};
</script>

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
Copy link
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).

Considerations:

  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate For issues that already existed in our issue tracker and were reported previously. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

2 participants