Brand tracking platforms monitor how consumers perceive your brand over time -- measuring awareness, sentiment, and competitive positioning. Building your own with web search and scraping APIs gives you full control over data sources, frequency, and analysis without paying enterprise SaaS fees.
This tutorial walks through building a brand tracking system using SearchHive's SwiftSearch API to monitor mentions across search results, news, and review sites.
Key Takeaways
- A custom brand tracker costs a fraction of enterprise platforms ($9-49/mo vs $500+/mo)
- SearchHive's SwiftSearch API provides real-time brand mention data from multiple engines
- ScrapeForge handles review sites that block simple HTTP requests
- Python + pandas makes analysis straightforward even at scale
- You can track unlimited brands on the free tier (500 credits/month)
Prerequisites
Before starting, you'll need:
- Python 3.8+ installed on your system
- SearchHive API key -- sign up free for 500 credits
- pip packages:
requests,pandas,matplotlib - Basic familiarity with Python and REST APIs
pip install requests pandas matplotlib
Step 1: Set Up Your SearchHive Client
Create a reusable client that wraps SearchHive's SwiftSearch and ScrapeForge APIs.
import requests
import time
from datetime import datetime, timedelta
class BrandTracker:
BASE_URL = "https://api.searchhive.dev/v1"
def __init__(self, api_key):
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
})
def search_brand(self, brand, query_extra=""):
resp = self.session.post(f"{self.BASE_URL}/search", json={
"query": f'"{brand}" {query_extra}',
"engine": "google",
"limit": 20
})
resp.raise_for_status()
return resp.json()
def search_news(self, brand):
resp = self.session.post(f"{self.BASE_URL}/search", json={
"query": f"{brand} news",
"engine": "google_news",
"limit": 20
})
resp.raise_for_status()
return resp.json()
def scrape_reviews(self, url):
resp = self.session.post(f"{self.BASE_URL}/scrape", json={
"url": url,
"format": "markdown"
})
resp.raise_for_status()
return resp.json()
This client handles authentication, retries, and response parsing. Store your API key in an environment variable:
import os
tracker = BrandTracker(os.environ["SEARCHHIVE_API_KEY"])
/tutorials/searchhive-api-quickstart
Step 2: Define Your Brand Tracking Queries
Build a query set that covers the dimensions you want to track.
BRAND = "SearchHive"
QUERIES = {
"general_mentions": f'"{BRAND}"',
"reviews": f'"{BRAND}" review',
"comparison": f'"{BRAND}" vs alternatives',
"pricing": f'"{BRAND}" pricing',
"sentiment_positive": f'"{BRAND}" best features',
"sentiment_negative": f'"{BRAND}" problems issues',
"competitors": f"search API alternatives to {BRAND}",
"integrations": f'"{BRAND}" API integration Python'
}
def run_tracking_cycle(tracker, brand, queries):
results = {}
for label, query in queries.items():
data = tracker.search_brand(brand, query.replace(f'"{brand}" ', "").replace(f"{brand} ", ""))
results[label] = {
"timestamp": datetime.utcnow().isoformat(),
"query": query,
"total_results": data.get("total_results", 0),
"top_titles": [r.get("title", "") for r in data.get("results", [])[:10]],
"top_urls": [r.get("url", "") for r in data.get("results", [])[:10]]
}
time.sleep(0.5) # Respect rate limits
return results
# Run your first tracking cycle
results = run_tracking_cycle(tracker, BRAND, QUERIES)
Step 3: Scrape Review Sites for Deeper Sentiment
Search results give you titles and snippets. For actual review content, use ScrapeForge to extract full pages.
def extract_review_sentiment(tracker, url):
scraped = tracker.scrape_reviews(url)
content = scraped.get("content", "").lower()
text = scraped.get("text", content)
positive_words = ["excellent", "great", "love", "recommend", "fast", "reliable", "affordable"]
negative_words = ["slow", "expensive", "buggy", "unreliable", "terrible", "worst", "disappointed"]
pos_count = sum(1 for w in positive_words if w in text)
neg_count = sum(1 for w in negative_words if w in text)
return {
"url": url,
"positive_hits": pos_count,
"negative_hits": neg_count,
"sentiment_score": (pos_count - neg_count) / max(1, (pos_count + neg_count))
}
# Scrape top 5 review URLs from search results
review_results = results.get("reviews", {})
review_urls = review_results.get("top_urls", [])[:5]
sentiments = []
for url in review_urls:
try:
sentiment = extract_review_sentiment(tracker, url)
sentiments.append(sentiment)
time.sleep(1)
except Exception as e:
print(f"Failed to scrape {url}: {e}")
avg_sentiment = sum(s["sentiment_score"] for s in sentiments) / len(sentiments) if sentiments else 0
print(f"Average sentiment score: {avg_sentiment:.2f} (-1 to +1)")
/tutorials/web-scraping-with-scrapeforge
Step 4: Build a Tracking History with Pandas
Store results over time to spot trends.
import pandas as pd
import json
from pathlib import Path
HISTORY_FILE = Path("brand_tracking_history.csv")
def save_tracking_results(results, brand):
rows = []
for label, data in results.items():
rows.append({
"date": datetime.utcnow().strftime("%Y-%m-%d"),
"brand": brand,
"category": label,
"total_results": data["total_results"],
"top_title": data["top_titles"][0] if data["top_titles"] else ""
})
df = pd.DataFrame(rows)
if HISTORY_FILE.exists():
existing = pd.read_csv(HISTORY_FILE)
df = pd.concat([existing, df], ignore_index=True)
df.to_csv(HISTORY_FILE, index=False)
print(f"Saved {len(rows)} data points. Total: {len(df)}")
return df
df = save_tracking_results(results, BRAND)
Step 5: Visualize Brand Mentions Over Time
After running tracking cycles over several days or weeks, visualize the trends.
import matplotlib.pyplot as plt
def plot_brand_trends(csv_path, brand):
df = pd.read_csv(csv_path)
brand_df = df[df["brand"] == brand]
# Pivot for time series
pivot = brand_df.pivot_table(
index="date", columns="category", values="total_results", aggfunc="first"
)
pivot.plot(figsize=(12, 6), marker="o")
plt.title(f"Brand Tracking: {brand}")
plt.ylabel("Search Result Count")
plt.xlabel("Date")
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig(f"{brand.lower()}_tracking_trend.png", dpi=150)
print("Chart saved")
# Run after collecting data over multiple days
# plot_brand_trends(HISTORY_FILE, BRAND)
Step 6: Automate with a Cron Schedule
Set up automated daily tracking runs.
# save as track_brand.py and run with cron: 0 9 * * * python3 track_brand.py
import os
def daily_tracking_job():
api_key = os.environ["SEARCHHIVE_API_KEY"]
tracker = BrandTracker(api_key)
results = run_tracking_cycle(tracker, BRAND, QUERIES)
df = save_tracking_results(results, BRAND)
# Alert if mentions spike or drop significantly
general_count = results.get("general_mentions", {}).get("total_results", 0)
if general_count < 100:
print(f"WARNING: Low mention count ({general_count})")
elif general_count > 10000:
print(f"SPIKE: High mention count ({general_count}) -- possible viral content")
if __name__ == "__main__":
daily_tracking_job()
Common Issues
Rate limiting: SearchHive enforces rate limits per plan. Use time.sleep(0.5) between calls. The Builder plan ($49/mo) raises limits significantly.
Blocked sites: Some review sites use aggressive bot protection. ScrapeForge handles most of these automatically via proxy rotation and browser rendering. If a scrape fails, the error response tells you why.
Sentiment accuracy: Word-count sentiment analysis is basic. For production use, combine it with a sentiment analysis model or NLP library like TextBlob.
Historical data: Search engines don't provide historical search result counts. Start tracking now to build your own historical dataset.
Next Steps
- Add competitor brands to your tracking queries for competitive intelligence
- Set up alerts when sentiment drops below a threshold
- Integrate with a dashboard tool (Grafana, Streamlit) for real-time monitoring
- Use SearchHive's DeepDive API for deeper content analysis of top mentions
Get Started Free
Build your own brand tracking platform with SearchHive's APIs. Sign up free and get 500 credits to start monitoring your brand today. The Starter plan at $9/month gives you 5,000 credits -- enough to track multiple brands daily. See the docs for complete API reference and code examples.