예제 #1
0
파일: Piwik.php 프로젝트: tillk/vufind
    /**
     * Get Site Search Tracking Code
     *
     * @param VuFind\Search\Base\Results $results Search results
     *
     * @return string JavaScript Code Fragment
     */
    protected function getTrackSearchCode($results)
    {
        $escape = $this->getView()->plugin('escapeHtmlAttr');
        $params = $results->getParams();
        $searchTerms = $escape($params->getDisplayQuery());
        $searchType = $escape($params->getSearchType());
        $resultCount = $results->getResultTotal();
        // Use trackSiteSearch *instead* of trackPageView in searches
        return <<<EOT
_paq.push(['trackSiteSearch', '{$searchTerms}', '{$searchType}', {$resultCount}]);

EOT;
    }
예제 #2
0
    /**
     * Get Site Search Tracking Code for Combined Search
     *
     * @param VuFind\Search\Base\Results $results         Search results
     * @param array                      $combinedResults Combined Search Results
     *
     * @return string JavaScript Code Fragment
     */
    protected function getTrackCombinedSearchCode($results, $combinedResults)
    {
        $escape = $this->getView()->plugin('escapeHtmlAttr');
        $params = $results->getParams();
        $searchTerms = $escape($params->getDisplayQuery());
        $searchType = $escape($params->getSearchType());
        $resultCount = 0;
        foreach ($combinedResults as $currentSearch) {
            if ($currentSearch['ajax']) {
                // Some results fetched via ajax, so report that we don't know the
                // result count.
                $resultCount = 'false';
                break;
            }
            $resultCount += $currentSearch['view']->results->getResultTotal();
        }
        // Use trackSiteSearch *instead* of trackPageView in searches
        return <<<EOT
    VuFindPiwikTracker.trackSiteSearch(
        'Combined|{$searchTerms}', '{$searchType}', {$resultCount}
    );

EOT;
    }