As Sherlock, I've designed and prototyped a complete, production-ready framework for detecting content decay on high-traffic sites (e.g., news, blogs, e-commerce). This system uses traffic cohorting to segment users, refresh prioritization to score update urgency, and a test-and-learn loop for validation. It's built for scalability with BigQuery/SQL for data processing, Python (Pandas/Scikit-learn) for modeling, and Airflow/DBT for orchestration.
Key Assumptions & Data Model
Data Sources: GA4/BigQuery events table with page_path, page_view_date, user_pseudo_id, publish_date, content_id.
Content Table: content_metadata with content_id, publish_date, category, author, word_count, last_updated.
Traffic Decay Signal: Weekly pageviews per content_id, cohort-normalized.
Cohort Definition: Users bucketed by first_visit_week to the site (e.g., "2024-W01"), capturing acquisition decay.
Decay Threshold: >20% traffic drop vs. expected (half-life model).
Tech Stack: BigQuery (queries), Python (scoring/ML), Google Sheets/Slack for alerts, Optimizely for A/B tests.
DAG Schedule: Daily cohorting, weekly decay scoring, bi-weekly tests.
1. Traffic Cohorting
Group traffic by user acquisition cohort (first site visit week) to isolate decay from new user growth.
BigQuery SQL (Run Weekly)
sql
-- Step 1: Compute user cohorts (first_visit_week)
CREATE OR REPLACE TABLE `project.dataset.user_cohorts` AS
WITH first_visit AS (
SELECT
user_pseudo_id,
MIN(EXTRACT(WEEK FROM TIMESTAMP_MICROS(event_timestamp))) AS cohort_week,
MIN(YEAR(TIMESTAMP_MICROS(event_timestamp))) AS cohort_year
FROM `project.analytics_123456789.events_*`
WHERE event_name = 'page_view'
GROUP BY user_pseudo_id
)
SELECT
user_pseudo_id,
FORMAT('20%02d-W%02d', cohort_year - 2000, cohort_week) AS cohort_id
FROM first_visit;
-- Step 2: Cohorted traffic per content (weekly)
CREATE OR REPLACE TABLE `project.dataset.cohorted_traffic` AS
WITH traffic AS (
SELECT
content_id, -- Extract from page_path or custom param
user_pseudo_id,
EXTRACT(YEEK FROM TIMESTAMP_MICROS(event_timestamp)) AS week_num,
EXTRACT(YEAR FROM TIMESTAMP_MICROS(event_timestamp)) AS year_num,
COUNT(*) AS pageviews
FROM `project.analytics_*.events_*`,
UNNEST([PARSE_JSON(event_params)]) AS params
WHERE params.key = 'page_location' AND REGEXP_CONTAINS(params.value.string_value, r'/content/(\d+)')
GROUP BY 1,2,3,4
)
SELECT
content_id,
cohort_id,
FORMAT('20%02d-W%02d', year_num - 2000, week_num) AS analysis_week,
SUM(pageviews) AS cohort_pageviews,
COUNT(DISTINCT user_pseudo_id) AS cohort_users
FROM traffic t
JOIN `project.dataset.user_cohorts` c ON t.user_pseudo_id = c.user_pseudo_id
GROUP BY 1,2,3;
Output: Table with ~10M rows (e.g., content_id=123, cohort='2024-W01', week='2024-W10', pageviews=5000).
2. Decay Detection
Fit an exponential decay model per cohort/content: traffic_t = traffic_0 * exp(-λ * age_weeks).
Detect if actual < expected by 2σ.
Python Script (Weekly Scoring)
python
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from scipy.optimize import curve_fit
import plotly.express as px
# Load data
df = pd.read_gbq("SELECT * FROM `project.dataset.cohorted_traffic` WHERE analysis_week >= '2024-W01'")
def exp_decay(x, a, b): # traffic = a * exp(-b * weeks_since_publish)
return a * np.exp(-b * x)
decay_scores = []
for (content_id, cohort), group in df.groupby(['content_id', 'cohort_id']):
group = group.sort_values('analysis_week')
group['age_weeks'] = (pd.to_datetime(group.analysis_week) - pd.to_datetime(group.iloc[0].analysis_week)).dt.days / 7
if len(group) < 4: continue # Need min data
# Fit decay curve
popt, _ = curve_fit(exp_decay, group.age_weeks, group.cohort_pageviews, p0=(group.cohort_pageviews.max(), 0.1))
# Predict current
current_age = group.age_weeks.max()
expected = exp_decay(current_age, *popt)
actual = group.cohort_pageviews.iloc[-1]
decay_ratio = (expected - actual) / expected if expected > 0 else 0
decay_scores.append({
'content_id': content_id,
'cohort': cohort,
'decay_ratio': decay_ratio,
'half_life_weeks': np.log(2) / popt[1] if popt[1] > 0 else np.inf,
'current_traffic': actual
})
decay_df = pd.DataFrame(decay_scores)
decay_df['decaying'] = decay_df.decay_ratio > 0.2 # Threshold
decay_df.to_gbq('project.dataset.decay_signals', if_exists='replace')
Visualization: Plotly line chart of actual vs. fitted decay per content/cohort.
Learn: Update regain_potential per category/author.
Implementation
Queue to Tests: Push top-20 to Optimizely/ABTest tool.
python
# Pseudo-Optimizely API
for idx, row in top_priority.head(20).iterrows():
create_ab_test(content_id=row.content_id, variant='refreshed')
Uplift Analysis (Post-Test SQL):
sql
-- Compare treatment vs control cohorts
SELECT
content_id,
AVG(CASE WHEN variant='treatment' THEN pageviews END) / AVG(CASE WHEN variant='control' THEN pageviews END) AS uplift_ratio
FROM test_results
GROUP BY content_id;
Feedback Loop: Retrain regain_potential quarterly with uplift data.
python
uplifts = pd.read_gbq("SELECT * FROM test_uplifts")
category_uplift = uplifts.groupby('category').uplift_ratio.mean()
# Persist to metadata
Monitoring & Dashboard
Looker/G Sheets: Priority queue, decay heatmaps (cohort x content).