Piwik\Tracker\VisitExcluded::isExcluded PHP Method

isExcluded() public method

Plugins can for example exclude visitors based on the - IP - If a given cookie is found
public isExcluded ( ) : boolean
return boolean True if the visit must not be saved, false otherwise
    public function isExcluded()
    {
        $excluded = false;
        if ($this->isNonHumanBot()) {
            Common::printDebug('Search bot detected, visit excluded');
            $excluded = true;
        }
        /*
         * Requests built with piwik.js will contain a rec=1 parameter. This is used as
         * an indication that the request is made by a JS enabled device. By default, Piwik
         * doesn't track non-JS visitors.
         */
        if (!$excluded) {
            $toRecord = $this->request->getParam($parameterForceRecord = 'rec');
            if (!$toRecord) {
                Common::printDebug(@$_SERVER['REQUEST_METHOD'] . ' parameter ' . $parameterForceRecord . ' not found in URL, request excluded');
                $excluded = true;
                Common::printDebug("'{$parameterForceRecord}' parameter not found.");
            }
        }
        /**
         * Triggered on every tracking request.
         *
         * This event can be used to tell the Tracker not to record this particular action or visit.
         *
         * @param bool &$excluded Whether the request should be excluded or not. Initialized
         *                        to `false`. Event subscribers should set it to `true` in
         *                        order to exclude the request.
         * @param Request $request The request object which contains all of the request's information
         *
         */
        Piwik::postEvent('Tracker.isExcludedVisit', array(&$excluded, $this->request));
        /*
         * Following exclude operations happen after the hook.
         * These are of higher priority and should not be overwritten by plugins.
         */
        // Checking if the Piwik ignore cookie is set
        if (!$excluded) {
            $excluded = $this->isIgnoreCookieFound();
            if ($excluded) {
                Common::printDebug("Ignore cookie found.");
            }
        }
        // Checking for excluded IPs
        if (!$excluded) {
            $excluded = $this->isVisitorIpExcluded();
            if ($excluded) {
                Common::printDebug("IP excluded.");
            }
        }
        // Check if user agent should be excluded
        if (!$excluded) {
            $excluded = $this->isUserAgentExcluded();
            if ($excluded) {
                Common::printDebug("User agent excluded.");
            }
        }
        // Check if Referrer URL is a known spam
        if (!$excluded) {
            $excluded = $this->isReferrerSpamExcluded();
            if ($excluded) {
                Common::printDebug("Referrer URL is blacklisted as spam.");
            }
        }
        // Check if request URL is excluded
        if (!$excluded) {
            $excluded = $this->isUrlExcluded();
            if ($excluded) {
                Common::printDebug("Unknown URL is not allowed to track.");
            }
        }
        if (!$excluded) {
            if ($this->isPrefetchDetected()) {
                $excluded = true;
                Common::printDebug("Prefetch request detected, not a real visit so we Ignore this visit/pageview");
            }
        }
        if ($excluded) {
            Common::printDebug("Visitor excluded.");
            return true;
        }
        return false;
    }

Usage Example

コード例 #1
0
ファイル: VisitTest.php プロジェクト: Michael2008S/piwik
 /**
  * @dataProvider getExcludeByUrlData
  */
 public function testExcludeByUrl($siteUrls, $excludeUnknownUrls, array $urlsTracked)
 {
     $siteId = API::getInstance()->addSite('name', $siteUrls, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, null, null, null, null, null, null, null, null, $excludeUnknownUrls);
     foreach ($urlsTracked as $url => $isTracked) {
         $visitExclude = new VisitExcluded(new Request(array('idsite' => $siteId, 'rec' => 1, 'url' => $url)));
         $this->assertEquals($isTracked, !$visitExclude->isExcluded(), $url . ' is not returning expected result');
     }
 }
All Usage Examples Of Piwik\Tracker\VisitExcluded::isExcluded