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

Piwik.js: ability to register plugins to execute logic when a request is sent #5393

Closed
mattab opened this issue Jul 1, 2014 · 3 comments
Closed
Assignees
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Jul 1, 2014

As a developer, I want to register function callbacks in Piwik.js Javascript tracking client, so that I can enrich the tracking requests with custom data, or do other custom logic whenever a request would be sent to the Tracking API (pageview, ecommerce, site search, etc.)

For more information see the tests here: https://github.com/piwik/piwik/pull/336/files

@mattab
Copy link
Member Author

mattab commented Jul 1, 2014

Message in forum post:

As I can read from piwik.js code, I'm not doing anything special with a plugin, just regular Tracker plugin functionality - depending on interaction type (click, load, unload, log, ...) append interaction type specific custom data to request query string, e.g. interaction type itself. Plugins are called for every Tracker.getRequest (line: "request += executePluginMethod(pluginMethod);"winking smiley.

I'm registering plugin with regular _paq.push([function() ....
Referencing Piwik singleton from such a function (e.g. to call addPlugin) will not work, because _paq array elements are evaluated in Piwik constructor, before Piwik is made accessible.

Calling addPlugin after piwik.js has been loaded is too late - I need plugin registered at construction time, before any interaction event has been tracked.

Moving/adding addPlugin from Piwik to Tracker public API, and making Tracker's addPlugin one of applyFirst methods, did the trick for me. I'm working on a pull request (which leaves addPlugin on Piwik singleton, but adds one on Tracker too).

@mattab
Copy link
Member Author

mattab commented Jul 1, 2014

In 2df1f90: Merge pull request #336 from sslavic/tracker_addPlugin

[piwik-js] Added support for registering plugins in Tracker public API fixes #5393

@mattab
Copy link
Member Author

mattab commented Jul 1, 2014

In ff475e5: add comment to function refs #5393
refs #336

@mattab mattab added this to the 2.4.0 - Piwik 2.4.0 milestone Jul 8, 2014
@mattab mattab self-assigned this Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

1 participant