After a long gap, I had the opportunity to dig into Piwik Analytics, the latest version (2.13.1), which has many new features from the last one we were using. During the time when implementing the same, I wanted to apply some custom variables, which showd the logged in user, the internal reference numbers and some other parameters. Whatever I did according to the documentations, the custom variables were not showing up.
My basic instinct, and the same reason why I shy away from other technologies than php when need arises, was to dig into the source code with grep, file_put_contents, print_r etc found that the custom vars were being sent to the server after encoding them as json strings. And at one point the strings were not being extracted to corresponding arrays, before validating for 2 count in array. Well this was modified with a forced decode to array from json string. I took the time to post this on the piwik forum as a bug. Not sure if it helps.
While diggin into the code, tracking led me to core/Tracker/Request.php method getCustomVariables($scope) line 540 or so.. where the $keyValue was being tested for count($keyValue) == 2 whereas it was still a json. From the js, it was being posted in as a dual json encoded so I added
$keyValue = json_decode($keyValue, 1);
above the validation condition, just inside the foreach loop.
Now things are working fine.