Custom variables in PHP 5.1.x

Hi all,

We’re using PHP 5.1.6. When using custom variables like:

$tracker->setCustomVariable( 1, ‘gender’, ‘male’ );

an error pops up saying:

Call to undefined function json_encode() in /PiwikTracker.php on line 814

That line contains this code:

(!empty($this->pageCustomVar) ? ‘&cvar=’ . urlencode(json_encode($this->pageCustomVar)) : ‘’) .

It seems that we cannot use custom vars unless we install the php json extension which is only available from PHP version 5.2.0. We would therefore have to upgrade our PHP installation which brings a risk for the websites we’re hosting on our server.

Is there a way around this which would allow us to use custom variables with PHP 5.1.6 ? Custom variables is a major Piwik feature for us, made us choose Piwik over Google analytics.

Any help is much appreciated!

use the json_encode function in libs/upgradephp/upgrade.php by including that file first

Wonderful, we will give that a go, thanks!