Bot View Counter in PHP
On the counter pages:
- 495 Unique Visitors
- 1,856 Page Views
- 82 Bot Views
- 2,388,390 Unique Visitors
- 3,480,617 Page Views
- 700,835 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.4M visitors 3.5M views 700.8K 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'])) {
}