Create an orphan page detector from logs, crawls, and analytics.
- User
Create an orphan page detector from logs, crawls, and analytics.
Assistant
Create an orphan page detector from logs, crawls, and analytics.
The user wants to "Create an orphan page detector from logs, crawls, and analytics." This is a data analysis task. I need to provide a solution, likely in code (Python is best for this) or a conceptual framework, that combines three data sources:
The Goal: Identify "Orphan Pages." What is an orphan page in this context?
Wait, let's refine the definition based on the inputs. Usually, an "Orphan Page" analysis involves finding pages that are live and accessible (found in Logs or Analytics) but missing from the Crawl (internal link structure).
Approach:
Data Ingestion:
Data Cleaning (Crucial Step):
Logic:
Python Implementation:
pandas for data manipulation.Output:
Refining the Solution Structure:
Drafting the Code Steps:
pd.merge(how='outer', indicator=True) is the most pandas-idiomatic way to do this.Self-Correction/Edge Cases:
Final Plan:
Let's write the code mentally first.
df_crawl = columns=['url']
df_logs = columns=['url', 'hits']
df_ga = columns['url', 'sessions']
Merge logs and GA to get "Active URLs".
Merge "Active URLs" with Crawl.
If url is in Active but not in Crawl -> Orphan.
This seems solid. I will present this clearly.
Structure of the response:
Let's refine the Python code to be robust.
clean_url(url): lowercase, strip protocol (maybe?), strip www (maybe?), strip trailing slash.Let's go. An Orphan Page is a page that exists on your server and may even receive traffic, but it has no internal links pointing to it from the rest of your website (it is isolated in your site architecture).
To detect these, you must cross-reference three data sources:
Here is a complete guide and a Python script to detect them.
All Known URLs minus Crawled URLs.This script uses pandas to process CSV exports from your tools (Screaming Frog, Google Analytics, Raw Logs).
Prerequisites:
pip install pandasimport pandas as pd
class OrphanDetector:
def __init__(self, crawl_file, logs_file, analytics_file):
self.crawl_file = crawl_file
self.logs_file = logs_file
self.analytics_file = analytics_file
def normalize_url(self, url):
"""
Standardizes URLs to ensure matching.
Removes protocol (http/https), www, and trailing slashes.
"""
if pd.isna(url):
return None
url = str(url).lower().strip()
# Remove protocol
url = url.replace('http://', '').replace('https://', '')
# Remove www
if url.startswith('www.'):
url = url[4:]
# Remove trailing slash
if url.endswith('/'):
url = url[:-1]
# Remove query params (optional, depends on your site structure)
# if '?' in url: url = url.split('?')[0]
return url
def load_data(self):
print("Loading data...")
# 1. Load Crawl Data (e.g., Screaming Frog)
# We assume the CSV has a column named 'Address'
try:
df_crawl = pd.read_csv(self.crawl_file, usecols=['Address'])
df_crawl['url'] = df_crawl['Address'].apply(self.normalize_url)
self.crawl_urls = set(df_crawl['url'].dropna().unique())
print(f" - Crawl URLs loaded: {len(self.crawl_urls)}")
except Exception as e:
print(f"Error loading crawl file: {e}")
self.crawl_urls = set()
# 2. Load Logs Data (e.g., ELK, Apache, Cloudflare)
# We assume the CSV has a column named 'url' or 'path'
try:
df_logs = pd.read_csv(self.logs_file)
# Attempt to find the URL column dynamically if named differently
# For this example, assuming a column named 'url'
df_logs['url'] = df_logs['url'].apply(self.normalize_url)
self.log_urls = set(df_logs['url'].dropna().unique())
print(f" - Log URLs loaded: {len(self.log_urls)}")
except Exception as e:
print(f"Error loading logs file: {e}")
self.log_urls = set()
# 3. Load Analytics Data (e.g., GA4, BigQuery)
# We assume the CSV has a column named 'pagePath'
try:
df_ga = pd.read_csv(self.analytics_file)
# In GA, paths are usually relative (/page), so we might need to append domain
# or strip domain from our master list. For this script, we assume Absolute URLs
# or you must pre-process GA export to include domain.
df_ga['url'] = df_ga['pagePath'].apply(self.normalize_url)
self.analytics_urls = set(df_ga['url'].dropna().unique())
print(f" - Analytics URLs loaded: {len(self.analytics_urls)}")
except Exception as e:
print(f"Error loading analytics file: {e}")
self.analytics_urls = set()
def find_orphans(self):
print("\nProcessing logic...")
# A. Combine Logs & Analytics (These are 'Real' pages)
# We only care about pages that are actually visited or generate server load.
real_pages = self.log_urls.union(self.analytics_urls)
print(f" - Total 'Real' Pages (Logs + Analytics): {len(real_pages)}")
# B. Identify Orphans
# Orphans = Pages that exist in Real set BUT NOT in Crawl set
orphans = real_pages - self.crawl_urls
print(f" - ORPHANS DETECTED: {len(orphans)}")
return sorted(list(orphans))
def save_report(self, orphans, output_file="orphan_pages.csv"):
df = pd.DataFrame(orphans, columns=['Orphan_URL'])
df.to_csv(output_file, index=False)
print(f"Report saved to {output_file}")
# ==========================================
# EXECUTION
# ==========================================
if __name__ == "__main__":
# Replace these with your actual file paths
# Files must be in CSV format
detector = OrphanDetector(
crawl_file='crawl_export.csv', # Screaming Frog export
logs_file='server_logs.csv', # Log export
analytics_file='analytics.csv' # GA export
)
detector.load_data()
orphans = detector.find_orphans()
if orphans:
detector.save_report(orphans)
else:
print("No orphans found (or data loading failed).")
The hardest part of this task is not the code, but the data normalization. Here is how to prepare the inputs:
Address.url./blog/post-1), while Crawls and Logs usually have absolute paths (example.com/blog/post-1).Once you have the list of Orphans, you can classify them to decide what to do:
example.com/products?ref=spam). These create duplicate content issues. Canonicalize them.