Hello piwik community,
What is recommended way to add some preprocessing logic on client side before request data is sent to tracker?
Kind regards,
Stevo Slavic.
Hello piwik community,
What is recommended way to add some preprocessing logic on client side before request data is sent to tracker?
Kind regards,
Stevo Slavic.
Hi Stevo, what are you trying to achieve in your case? if we know more about what you want to achieve we could help you see how it can be done with Piwik
I’d like piwik.js to track events first to a non-piwik tracker, a REST service, which can optionally forward requests to piwik tracker. Both custom URL and POST method are configurable in piwik.js Tracker, but not manipulating request content - I’d like to convert request parameters string to JSON string.
I tried proxying Tracker’s getRequest public method (getRequest with one, request parameter), but that didn’t help - all the log methods like logPageView method use private getRequest method with 4 parameters. I wonder what’s the purpose of public getRequest method, but most importantly, am I missing something or request content cannot be manipulated (without changing piwik.js itself)?
Kind regards,
Stevo Slavic.
Hi Stevo,
I think this is a new feature request. it makes sense that Piwik.js should allow you to change the request. Do you have an idea of how this could be done in Piwik.js ? (I’m asking about how you think the piwik.js API / new function should look like ?)
Hello Matt,
One approach would be to make 4 param getRequest public (remove existing single param public getRequest), so one can implement a getRequest proxy/decorator which will delegate to original getRequest and then call custom logic before returning result.
I’m most in favor of this approach.
A different approach would be to introduce a new public method (called e.g. processRequestContent), a callback/hook which would get called:
Matt, and rest of community, which approach/option do you prefer?
I’ll play around locally with some of these approaches/options. Maybe something becomes good enough for pull request.
Kind regards,
Stevo Slavic.
I’ve just submitted a pull request (see #325 ) which adds a new configuration option for configuring custom request content processing logic.
Kuddos for the pull request sslavic! We hope you will keep contributing good ideas to Piwik