Bot View Counter in PHP

On the counter pages:

  • 1,248 Unique Visitors
  • 3,224 Page Views
  • 167 Bot Views
  • 5,996,897 Unique Visitors
  • 8,647,337 Page Views
  • 2,334,837 Bot Views

Sometimes your site gets a lot of traffic, but it's not traffic coming from real people.

This addition to the Unique Visitor Counter and Pageview Counter is an extra counter category that only counts views from bots.

6M visitors 8.6M views 2.3M bots

Source Code

Note: This is a function that you can wrap around code to only apply if the user agent detects a bot from a list of known bots.

PHP

// Function to check if the user agent is a bot
function isBot($userAgent) {
$bots = [
'Googlebot',
'Bingbot',
'Slurp',
'DuckDuckBot',
'Baiduspider',
'YandexBot',
'Sogou',
'Exabot',
'Facebot',
'ia_archiver',
'Twitterbot',
'LinkedInBot',
'Applebot',
'AhrefsBot',
'SemrushBot',
'MJ12bot',
'DotBot',
'BLEXBot',
'Coccinelle',
'BingPreview',
'MetaGer',
'Grapeshot',
'NuzzelBot',
'Screaming Frog SEO Spider',
'W3C Validator',
'Archive.org Bot',
'ChatGPT', // AI Bot
'Bard', // AI Bot
'Claude', // AI Bot
'Jasper', // AI Bot
'Copy.ai', // AI Bot
'DeepAI', // AI Bot
'OpenAI API', // AI Bot
'Replika', // AI Bot
'Kuki', // AI Bot
'Cleverbot', // AI Bot
'Yandex', // Russian Search Engine
'Baidu', // Chinese Search Engine
'Ahrefs', // SEO Tool
// 'Moz', // SEO Tool
'SEMrush', // SEO Tool
'Netcraft', // Internet Services
'Quantcast', // Audience Measurement
'StatCounter', // Web Analytics
'Google PageSpeed Insights', // Performance Analysis
'Google Analytics',
'Piwik',
'Clicky',
'Sucuri',
'Cloudflare',
'Qualys',
'BingImageCreator', // Additional Bot
'PinterestBot', // Additional Bot
'Slackbot', // Additional Bot
'Google AdsBot' // Additional Bot
];
foreach ($bots as $bot) {
if (stripos($userAgent, $bot) !== false) {
return true;
}
}
return false;
}

// Proceed only if the user agent is a bot
if (isBot($_SERVER['HTTP_USER_AGENT'])) {

}