DEV Community

Cover image for Detecting Fake Website Traffic: Building a Bot Traffic Detector with Python
SerpSpur
SerpSpur

Posted on

Detecting Fake Website Traffic: Building a Bot Traffic Detector with Python

Ever stared at your analytics and wondered if that sudden traffic spike is real? I did too, until I dug into referrer logs and found 80% of "visitors" were residential proxy botnets.

Let's build a quick fake traffic checker you can run locally.

The Signals That Matter

Real traffic has patterns. Bots don't. Here's what I check:

python
import re
from collections import Counter

def analyze_referrers(log_entries):
toxic_patterns = [
r'semalt.com', r'darodar.com', r'buttons-for-website',
r'rank.tracker', r'social-buttons.com'
]
suspicious = Counter()
for entry in log_entries:
ref = entry.get('referrer', '')
for pattern in toxic_patterns:
if re.search(pattern, ref, re.I):
suspicious[ref] += 1
return suspicious

The 4-Pillar Approach

A proper fake traffic audit looks at four dimensions:

  1. Session Depth – Bots bounce in under 2 seconds. Real users scroll.
  2. Referrer Authenticity – Cross-check referrers against known bot networks.
  3. CTR Anomalies – Sudden impression-to-click ratios that defy physics.
  4. Geo/IP Consistency – Residential proxies cluster in weird ASNs.

python
def compute_tai(sessions):
depth_score = sum(s['duration'] > 30 for s in sessions) / len(sessions)
bounce_score = 1 - sum(s['bounces'] for s in sessions) / len(sessions)
return round((depth_score * 0.4 + bounce_score * 0.6) * 100)

Why This Matters

Fake website traffic inflates vanity metrics but poisons your data. It skews keyword research, wastes ad spend, and can trigger Google penalties if CTR manipulation is detected.

The 0–100 Traffic Authenticity Index (TAI) gives you a single number to track. Anything below 70 deserves investigation.

Scaling It Up

Running this manually gets old fast. I've been using SERPSpur's TAI Checker to audit any domain instantly — it runs the 4-pillar forensics, generates a GSC disavow list, and estimates real traffic value. Way faster than rolling your own log parser for every client.

Start with the script above. If you find your TAI is tanking, automate the audit before your rankings do.

Top comments (0)