Any change to change behavior of function 'Piwik\Tracker\Settings->getConfigHash()'


(Chris Lee) #1

hi,

we’re trying to change the behavior of Piwik\Tracker\Settings->getConfigHash(), due to our tracking logics.

currently we fork origin piwik source code to change directly. but we can not upgrade piwik easily anymore.

so we want to know, is there an any chance to do this by piwik plugin ?


(Matthieu Aubry) #2

What are you trying to achieve and how do you want to change this config hash?


(Chris Lee) #3

Hi, @matthieu

Because we find out we had a lot of coworkers that had same third party visitorId cookie in our office .

At last, we figure out “getConfigHash()” is the root casue .

A lot of coworkers had the same configId .

Because we do not knows is this a bug ? or a expect behavior ?

And It’s happened on production server .

So we try to do the workaround by using plugin .

And We did found the way to achieve,

By create class that extends \Piwik\Plugins\CoreHome\Tracker\VisitRequestProcessor, and namespace is \Piwik\Plugins\MyPlugins\Tracker.

FYI.

Chris.


(Paweł Dysput) #4

Hi Chris

I have similar problem with recognizing unique users and need to modify configHash a bit.
Can you tell me how exactly you resolve this problem?

You created Tracker/VisitRequestProcessor.php inside your plugin dir and override processRequestParams method, am i right?

I will be gratefull if you share your code :slight_smile:

Paweł


(Chris Lee) #5

Hi, sorry for delay reply.

I Tracker/VisitRequestProcessor.php inside your plugin dir and also Tracker/Settings.php

I do overwrite the protected function getConfigHash inside Tracker/Settings.php

And pass Tracker/Settings class object to Tracker/VisitRequestProcessor.php construct.

here is code of Tracker/Settings.php

<?php

namespace Piwik\Plugins\CnyesVistorUserIdMapping\Tracker;

use \Piwik\Config;
use \Piwik\Tracker;
use \Piwik\Tracker\Settings;
use \Piwik\Tracker\Request;
use \Piwik\Log;
use \Piwik\Common;

class CnyesSettings extends Settings
{
    public function __construct()
    {
        parent::__construct((bool) Config::getInstance()->Tracker['enable_fingerprinting_across_websites']);
    }

    protected function getConfigHash(
        Request $request,
        $os,
        $browserName,
        $browserVersion,
        $plugin_Flash,
        $plugin_Java,
        $plugin_Director,
        $plugin_Quicktime,
        $plugin_RealPlayer,
        $plugin_PDF,
        $plugin_WindowsMedia,
        $plugin_Gears,
        $plugin_Silverlight,
        $plugin_Cookie,
        $ip,
        $browserLang
    ) {
        $configString = uniqid();
        $hash = md5($configString, $raw_output = true);
        $hash = substr($hash, 0, Tracker::LENGTH_BINARY_ID);
        Common::printDebug('CnyesSettings getConfigHash Hash = ' . @bin2hex($hash));
        return $hash;
    }
}

PS: my plugin is based on matomo 2.17.0


(Paweł Dysput) #6

I’m updating few big PIWIKs from 1.11 and 2.14 to the newest version.
I’m trying to do everything in a right way without modify core.
I think your code and tips will be very helpful. Thanks a lot Chris :slight_smile: