Detect product trend decay by monitoring how search result freshness and volume change over time for a given product query. When a product is trending, search results are dominated by recent articles, reviews, and social mentions. As interest decays, fresh content stops appearing and older results climb in rankings. This tutorial builds a trend decay detector that scores result freshness on a daily basis and alerts when the freshness score drops below a threshold, signaling that a product's peak interest has passed.
Prerequisites
- Python 3.8+ installed
- requests library installed
- A Scavio API key from scavio.dev
- A list of products to monitor for trend decay
Walkthrough
Step 1: Define products to monitor
Set up the products and the freshness scoring parameters.
import os, requests, json, datetime, re
API_KEY = os.environ['SCAVIO_API_KEY']
PRODUCTS = [
'Rabbit R1',
'Humane AI Pin',
'Meta Ray-Ban smart glasses',
'Apple Vision Pro',
]
CURRENT_YEAR = 2026
HISTORY_FILE = 'trend_decay.json'Step 2: Score result freshness
Search for each product and calculate a freshness score based on how many results mention the current or previous year.
def freshness_score(product: str) -> dict:
resp = requests.post('https://api.scavio.dev/api/v1/search',
headers={'x-api-key': API_KEY},
json={'platform': 'google', 'query': f'{product} review'}, timeout=15)
results = resp.json().get('organic_results', [])
fresh = 0
for r in results[:10]:
text = f"{r.get('title', '')} {r.get('snippet', '')}"
if str(CURRENT_YEAR) in text or str(CURRENT_YEAR - 1) in text:
fresh += 1
score = round(fresh / max(len(results[:10]), 1), 2)
return {'product': product, 'freshness': score, 'fresh_count': fresh, 'total': min(len(results), 10)}Step 3: Track scores over time
Save daily freshness scores to a history file and compute the trend direction (improving, stable, or decaying).
def track_trends(products: list) -> list:
today = datetime.date.today().isoformat()
scores = [freshness_score(p) for p in products]
for s in scores:
s['date'] = today
history = []
try:
with open(HISTORY_FILE) as f:
history = json.load(f)
except FileNotFoundError:
pass
history.extend(scores)
with open(HISTORY_FILE, 'w') as f:
json.dump(history, f, indent=2)
return scores
scores = track_trends(PRODUCTS)
for s in scores:
print(f"{s['product']}: freshness={s['freshness']} ({s['fresh_count']}/{s['total']} fresh results)")Step 4: Detect decay and alert
Compare today's freshness against the 7-day average to detect decay. Alert when freshness drops by more than 20%.
def detect_decay(product: str, threshold: float = 0.2) -> dict:
try:
with open(HISTORY_FILE) as f:
history = json.load(f)
except FileNotFoundError:
return {'product': product, 'status': 'insufficient_data'}
product_history = [h for h in history if h['product'] == product]
if len(product_history) < 3:
return {'product': product, 'status': 'insufficient_data'}
recent = product_history[-1]['freshness']
avg = sum(h['freshness'] for h in product_history[-7:]) / len(product_history[-7:])
decline = round(avg - recent, 2)
decaying = decline > threshold
return {
'product': product,
'current_freshness': recent,
'avg_freshness': round(avg, 2),
'decline': decline,
'decaying': decaying,
'status': 'DECAYING' if decaying else 'stable',
}
for p in PRODUCTS:
result = detect_decay(p)
print(f"{result['product']}: {result['status']}")Python Example
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def freshness(product):
data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
json={'platform': 'google', 'query': f'{product} review'}).json()
results = data.get('organic_results', [])[:10]
fresh = sum(1 for r in results if '2026' in f"{r.get('title', '')} {r.get('snippet', '')}")
return {'product': product, 'freshness': round(fresh / max(len(results), 1), 2)}
for p in ['Rabbit R1', 'Apple Vision Pro']:
print(freshness(p))JavaScript Example
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function freshness(product) {
const r = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: H, body: JSON.stringify({platform: 'google', query: `${product} review`})
});
const results = ((await r.json()).organic_results || []).slice(0, 10);
const fresh = results.filter(r => `${r.title} ${r.snippet}`.includes('2026')).length;
return {product, freshness: (fresh / Math.max(results.length, 1)).toFixed(2)};
}
freshness('Apple Vision Pro').then(console.log);Expected Output
A trend decay detection system that monitors product freshness scores daily and alerts when interest is declining based on the absence of recent content in search results.