diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 8a79b62b643ca4fc5c5f2f06a8a00f0e16702f07..390e4b73d67aa412783b8881abd5189297f555f1 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -1495,6 +1495,12 @@ treeSearchLimit = 100 ; Uncomment the following setting to track additional information about searches ; and displayed records with Piwik's custom variables ;custom_variables = true +; By default, Piwik searches are tracked using the format "Backend|Search Terms." +; If you need to differentiate searches coming from multiple VuFind instances using +; a shared site_id, you can set the searchPrefix to add an additional prefix to +; the string, for example "SiteA|Backend|Search Terms." Most users will want to +; leave this disabled. +;searchPrefix = "SiteA|" ; Uncomment portions of this section to activate tabs in the search box for switching ; between search modules. Keys are search backend names, values are labels for use in diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php index 4987ebb9aceb27b91ff56e756b9dff98b085c4e0..75f036f557c2d2e740047bdbf72ed6e6133da0d5 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php @@ -245,13 +245,17 @@ class Factory { $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); $url = isset($config->Piwik->url) ? $config->Piwik->url : false; - $siteId = isset($config->Piwik->site_id) ? $config->Piwik->site_id : 1; + $options = [ + 'siteId' => isset($config->Piwik->site_id) ? $config->Piwik->site_id : 1, + 'searchPrefix' => isset($config->Piwik->searchPrefix) + ? $config->Piwik->searchPrefix : null + ]; $customVars = isset($config->Piwik->custom_variables) ? $config->Piwik->custom_variables : false; $request = $sm->getServiceLocator()->get('Request'); $router = $sm->getServiceLocator()->get('Router'); - return new Piwik($url, $siteId, $customVars, $router, $request); + return new Piwik($url, $options, $customVars, $router, $request); } /** diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php b/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php index c628b764ffb9474de4d5d22e243d134d0e45cc3b..c69324b309de3b510f64cf8a564609c9ce85ceb7 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Piwik.php @@ -52,6 +52,13 @@ class Piwik extends \Zend\View\Helper\AbstractHelper */ protected $siteId; + /** + * Search prefix (see config.ini for details) + * + * @var string + */ + protected $searchPrefix; + /** * Whether to track use custom variables to track additional information * @@ -100,19 +107,26 @@ class Piwik extends \Zend\View\Helper\AbstractHelper * * @param string|bool $url Piwik address * (false if disabled) - * @param int $siteId Piwik site ID + * @param int|array $options Options array (or, + * if a single value, the Piwik site ID -- for backward compatibility) * @param bool $customVars Whether to track * additional information in custom variables * @param Zend\Mvc\Router\Http\RouteMatch $router Request * @param Zend\Http\PhpEnvironment\Request $request Request */ - public function __construct($url, $siteId, $customVars, $router, $request) + public function __construct($url, $options, $customVars, $router, $request) { $this->url = $url; if ($url && substr($url, -1) != '/') { $this->url .= '/'; } - $this->siteId = $siteId; + if (is_array($options)) { + $this->siteId = $options['siteId']; + $this->searchPrefix = isset($options['searchPrefix']) + ? $options['searchPrefix'] : ''; + } else { + $this->siteId = $options; + } $this->customVars = $customVars; $this->router = $router; $this->request = $request; @@ -511,7 +525,7 @@ EOT; // Use trackSiteSearch *instead* of trackPageView in searches return <<<EOT VuFindPiwikTracker.trackSiteSearch( - '$backendId|$searchTerms', '$searchType', $resultCount + '{$this->searchPrefix}$backendId|$searchTerms', '$searchType', $resultCount ); EOT; @@ -546,7 +560,7 @@ EOT; // Use trackSiteSearch *instead* of trackPageView in searches return <<<EOT VuFindPiwikTracker.trackSiteSearch( - 'Combined|$searchTerms', '$searchType', $resultCount + '{$this->searchPrefix}Combined|$searchTerms', '$searchType', $resultCount ); EOT;