diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php b/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php
index 99ea13b4ded4225440fb92f0580cb2eee3f127bc..64ff02545a54399a095c15871b262902a6d43e48 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php
@@ -329,6 +329,13 @@ EOT;
         $i = 0;
         foreach ($customVars as $key => $value) {
             ++$i;
+
+            // Workaround to prevent overwriting of custom variables 4 and 5 by
+            // trackSiteSearch, see http://forum.piwik.org/read.php?2,115537,115538
+            if ($i === 4) {
+                $i = 6;
+            }
+
             $value = $escape($value);
             $code .= <<<EOT
 _paq.push(['setCustomVariable', $i, '$key', '$value', 'page']);