Brutal fix for “Incorrect string value:” error in Matomo (Piwik)

If you’re using Matomo (previously Piwik) on MS IIS and MariaDB  and you’re getting a lot of these:

[06-Jun-2018 11:56:36 UTC] Error in Matomo (tracker): Error query: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xC3_\xC6\x92\xC3\x82...' for column 'name' at row 1 In query: INSERT INTO matomo_log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array (   0 => 'website.com/Ă_ƒÂ¢',   1 => 'website.com/Ă_ƒÂ¢',   2 => 1,   3 => 1, )

You can use my fix (because literally nothing that can be found in the internet is helpful in this case).

Brutal fix:

Open this file:

piwik\core\Tracker\Model.php

And find:

public function createNewIdAction($name, $type, $urlPrefix)

Now add this statement below my comment omit actions with…

public function createNewIdAction($name, $type, $urlPrefix)
{
# Omit actions with broken UTF-8 strings
if(!mb_detect_encoding($name, 'UTF-8', true)) {
return;
}

$newActionId = $this->insertNewAction($name, $type, $urlPrefix);

$realFirstActionId = $this->getIdActionMatchingNameAndType($name, $type);

// if the inserted action ID is not the same as the queried action ID, then that means we inserted
// a duplicate, so remove it now
if ($realFirstActionId != $newActionId) {
$this->deleteDuplicateAction($newActionId);
}

return $realFirstActionId;
}

It will simply omit broken records. Seriously, I don’t know if this is a good solution but I tried everything… I’ve even converted my database to UTF8mb4. After this edit it works like a charm!

Now you can call yourself a hacker!
voilà!

Published by

Konrad Fedorczyk

Konrad Fedorczyk

I'm interested in programming and gamedev. I especially luv HTML5 and everything connected to web technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *