Bot View Counter in PHP

On the counter pages:

  • 594 Unique Visitors
  • 2,037 Page Views
  • 86 Bot Views
  • 2,633,918 Unique Visitors
  • 3,908,502 Page Views
  • 807,239 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.

2.6M visitors 3.9M views 807.2K 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'])) {

}