Skip to content

Commit

Permalink
use DeviceDetector's bot parser to look for bots
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed May 29, 2014
1 parent e1abcdd commit 69892f5
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions core/Tracker/VisitExcluded.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace Piwik\Tracker;

use DeviceDetector\Parser\Bot;
use Piwik\Common;
use Piwik\Config;
use Piwik\IP;
Expand Down Expand Up @@ -73,9 +74,9 @@ public function isExcluded()

/**
* 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.
Expand Down Expand Up @@ -147,32 +148,19 @@ protected function isPrefetchDetected()
* As a result, these sophisticated bots exhibit characteristics of
* browsers (cookies enabled, executing JavaScript, etc).
*
* @see \DeviceDetector\Parser\Bot
*
* @return boolean
*/
protected function isNonHumanBot()
{
$allowBots = $this->request->getParam('bots');

return !$allowBots
// Seen in the wild
&& (strpos($this->userAgent, 'Googlebot') !== false // Googlebot
|| strpos($this->userAgent, 'Google Web Preview') !== false // Google Instant
|| strpos($this->userAgent, 'AdsBot-Google') !== false // Google Adwords landing pages
|| strpos($this->userAgent, 'Google Page Speed Insights') !== false // #4049
|| strpos($this->userAgent, 'Google (+https://developers.google.com') !== false // Google Snippet https://developers.google.com/+/web/snippet/
|| strpos($this->userAgent, 'facebookexternalhit') !== false // http://www.facebook.com/externalhit_uatext.php
|| strpos($this->userAgent, 'baidu') !== false // Baidu
|| strpos($this->userAgent, 'bingbot') !== false // Bingbot
|| strpos($this->userAgent, 'BingPreview') !== false // BingPreview
|| strpos($this->userAgent, 'YottaaMonitor') !== false // Yottaa
|| strpos($this->userAgent, 'CloudFlare') !== false // CloudFlare-AlwaysOnline
$botParser = new Bot($this->userAgent);
$botParser->discardDetails();

// Added as they are popular bots
|| strpos($this->userAgent, 'pingdom') !== false // pingdom
|| strpos($this->userAgent, 'yandex') !== false // yandex
|| strpos($this->userAgent, 'exabot') !== false // Exabot
|| strpos($this->userAgent, 'sogou') !== false // Sogou
|| strpos($this->userAgent, 'soso') !== false // Soso
return !$allowBots
&& ($botParser->parse() === true
|| IP::isIpInRange($this->ip, $this->getBotIpRanges()));
}

Expand Down

0 comments on commit 69892f5

Please sign in to comment.