Bot View Counter in PHP
On the counter pages:
- 310 Unique Visitors
- 670 Page Views
- 57 Bot Views
- 1,619,181 Unique Visitors
- 2,178,924 Page Views
- 454,093 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.
1.6M visitors 2.2M views 454.1K 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'])) {
}