Elegant way to Override Core functions?

(Jon) #1


We would need to override the behaviour of a Core function and were wondering what is the most elegant way to do it.

Especifically we need to change function getVisitorId in Core/Tracker/Request.php. In this function if a UserId is received by the tracker, a visitorId is created based on the hashed UserId. We need that the visitorId that is used is the one received in the cookie and not based on the UserID.

Therefore we would comment the following lines:
// If User ID is set it takes precedence
$userId = $this->getForcedUserId();
if ($userId) {
$userIdHashed = $this->getUserIdHashed($userId);
$idVisitor = $this->truncateIdAsVisitorId($userIdHashed);
Common::printDebug(“Request will be recorded for this user_id = " . $userId . " (idvisitor = $idVisitor)”);
$found = true;

Is there a way to change this without modifying it in the Core and preventing to loose these changes with future Piwik version updates?

Thank you in advance


(Matthieu Aubry) #2

Hi Jon,

Currently there is no way to change this without changing core. Maybe we should allow for your use case in core? If you think this makes sense for PIwik to manage your use case (ie. use the specified idvisitor in cookie rather than create a idvisitor based on user id) please create a new issue @ Issues · matomo-org/piwik · GitHub