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

Refactor tracker code so tracking code that handles request parameters can be organized by plugins #8071

Closed
4 of 12 tasks
diosmosis opened this issue Jun 9, 2015 · 8 comments
Assignees
Labels
answered For when a question was asked and we referred to forum or answered it. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.

Comments

@diosmosis
Copy link
Member

The purpose of this issue is to refactor the tracker so code relevant to plugins (eg, goal/conversion tracking, action tracking, etc.) are put into their respective plugins (eg, Goals, Actions).

To accomplish this, we can refactor Visit::handle() and introduce a new concept of a RequestProcessor which plugins implement to handle tracker request parameters. Unlike dimensions, these parameters do not have to be stored in the DB, and unlike Handlers, these parameters do not require an entirely different tracking mechanism (ie, QueuedTracking).

TODO:

  • introduce a new RequestProcessor interface which plugins implement (and add to DI). has the following methods:

    • processRequestParams(VisitProperties properties, Request request): implementations get information from request and store in visit properties (things like Actions detected, is manual goal conversion, is ecommerce, etc.). VisitProperties is a new class to be introduced, stores variables currently local vars in Visit::handle() or stored as properties in GoalManager.
    • handleRequest(VisitProperties properties): deduce other visit properties based on detected request information (eg, is new visit, goals converted due to action in request, etc.).
    • afterVisitHandled(VisitProperties properties): do non visit related things (like record conversions).
  • use the RequestProcessors in Visit::handle() as follows:

    • call processRequestParams() on all request processors to get info from request
    • recognize visitor, turn list of actions into single action (this is done in Action::factory)
    • call handleRequest() on all request processors to determine if visit is new, + other stuff needed
    • handle visit (either existing or new)
    • handle action
    • call afterVisitHandled()
  • move goal tracking code to Goals plugin & move action tracking code to Actions plugin

  • Move ping=1 tracker handling to a new plugin. When doing so, make sure ping=1 will ignore all goal related logic to be faster.

  • Move Action class & related code to Actions plugin. Move GoalManager to Goals plugin. Move other plugin related code to plugins from core.

  • Move current code to insert/update visit data in core to CoreHome. To do this correctly, would need a new service (eg, VisitRecorder), so VisitRequestProcessor does not get bloated (or more bloated).

  • Remove lots of tracking events, I think many (if not most) are no longer needed.

  • Create a new method in RequestProcessor specifically for manipulating request metadata. Right now, afterRequestProcessed() is used for both defining metadata that depends on other plugins' metadata and for manipulating other plugins' metadata. This means metadata that uses other plugins' metadata, can't be manipulated. Order of plugins will be come a problem eventually if many plugins get involved together...

  • Refactor the system again for clarity and ease of use. This makes it possible to split up the code and correctly scope classes, but the code is still verbose and the tracking logic is still not obvious. Before the system is made @api it should be made as easy to use as possible.

  • After it is possible to inject "component" types, RequestProcessors should use the "component" scheme.

  • Decouple VisitorRecognizer from Tracker classes and add integration test for it.

  • Do not use multi-dimensional array of properties for request metadata, instead use array of classes defined by plugins, so:

    /** @var $data MyPluginRequestMetadata */
    $data = $request->getMetadata('MyPlugin');
    
@diosmosis diosmosis added the c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. label Jun 9, 2015
@diosmosis diosmosis added this to the 3.0.0 milestone Jun 9, 2015
@mnapoli
Copy link
Contributor

mnapoli commented Jun 9, 2015

Sounds very good.

Why do the RequestProcessor need the 3 separate methods? Could you explain why all that they contain can't be done in one method?

@diosmosis
Copy link
Member Author

Why do the RequestProcessor need the 3 separate methods? Could you explain why all that they contain can't be done in one method?

The current logic (all in Piwik\Tracker\Visit::handle()) requires it. At least it's required to separate action + goals logic. For example, actions have to be determined before URL matching goals can be converted. But, manual goal conversion and ecommerce conversion has to be detected before actions, because in this case we don't record an action. This is the reason for processRequestParams()/handleRequest(), the first just gets info from the request (ie, actions in request, is it a goal conversion?, is it an ecommerce conversion?) then the second uses that information to deduce more info (based on the actions, is it a goal conversion?).

The third method exists because inserting custom logs has to be done after visits are handled. So recording actions is done after a visit, and recording conversions after the visit.

I don't want to change existing tracker behaviour in any way, just reorganize it.

@mattab
Copy link
Member

mattab commented Jun 10, 2015

+1 for the general idea to move more logic from Tracker core into the plugins. I really hope we can make it happen for 3.0.0!

@mnapoli
Copy link
Contributor

mnapoli commented Jun 10, 2015

Thanks for the explanation. Regarding the fact that this interface will be implemented by plugins, it might make sense to make it an abstract class instead (to allow a little more flexibility later to add new methods)?

@diosmosis
Copy link
Member Author

Abstract class sounds ok to me :)

@mattab
Copy link
Member

mattab commented Jun 26, 2015

make sure ping=1 will ignore all goal related logic to be faster.

done in #8223

@diosmosis diosmosis self-assigned this Jul 6, 2015
@mattab mattab modified the milestones: 3.0.0, 3.0.0-b1 Jul 30, 2015
diosmosis added a commit that referenced this issue Aug 7, 2015
Refs #8071, refactor tracker code for clarity, modularity and so plugins can have more granular control over tracking. Introduce RequestProcessor & request metadata concepts & use to split up Visit::handle() method so tracking logic is located in the relevant plugins.
@diosmosis diosmosis reopened this Aug 7, 2015
@mattab
Copy link
Member

mattab commented Aug 13, 2015

@diosmosis after we make it API (or some of it), can you please check the developer guides cover this new official ways of extending Tracker? https://github.com/piwik/developer-documentation/pull/100/files

@mattab mattab modified the milestones: 3.0.0, 3.0.0-b1 Oct 1, 2015
@mattab
Copy link
Member

mattab commented Jul 8, 2016

Part of the issue was done, the rest is "wontfix" until we need it. Likely we'll refactor these Tracker APIs in a later major Piwik version

@mattab mattab closed this as completed Jul 8, 2016
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Projects
None yet
Development

No branches or pull requests

3 participants