Introduction
Knowing where you rank on Google is essential for SEO. But checking manually is tedious, and paid tools (Ahrefs, SEMrush) cost $100+/month. Free rank tracking with Google Search Console + Python gives you the same data at zero cost.
This post builds an automated rank tracking system.
Step 1: Set up Google Search Console
- Go to search.google.com/search-console
- Add your property (website URL)
- Verify ownership (HTML file, DNS, or Google Analytics)
- Wait 2-3 days for data to populate
Step 2: Fetch rankings (Python)
from googleapiclient.discovery import build
from google.oauth2 import service_account
from datetime import datetime, timedelta
creds = service_account.Credentials.from_service_account_file(
"service_account.json",
scopes=["https://www.googleapis.com/auth/webmasters.readonly"],
)
service = build("searchconsole", "v1", credentials=creds)
def get_rankings(site_url, days=7):
"""Fetch keyword rankings from Google Search Console."""
end_date = datetime.now().date()
start_date = end_date - timedelta(days=days)
request = {
"startDate": str(start_date),
"endDate": str(end_date),
"dimensions": ["query"],
"rowLimit": 100,
}
response = service.searchanalytics().query(siteUrl=site_url, body=request).execute()
rows = response.get("rows", [])
rankings = []
for row in rows:
rankings.append({
"keyword": row["keys"][0],
"position": round(row["position"], 1),
"clicks": row["clicks"],
"impressions": row["impressions"],
"ctr": round(row["ctr"] * 100, 2),
"date": str(end_date),
})
return rankings
# Usage
rankings = get_rankings("https://techwithgalvan.in")
for r in rankings[:10]:
print(f"{r['keyword']}: pos {r['position']} ({r['clicks']} clicks, {r['impressions']} impressions)")
Step 3: Store history (SQLite)
import sqlite3
def init_db():
conn = sqlite3.connect("rankings.db")
conn.execute("""
CREATE TABLE IF NOT EXISTS rankings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
keyword TEXT,
position REAL,
clicks INTEGER,
impressions INTEGER,
ctr REAL,
date TEXT,
UNIQUE(keyword, date)
)
""")
conn.commit()
conn.close()
def save_rankings(rankings):
conn = sqlite3.connect("rankings.db")
for r in rankings:
conn.execute("""
INSERT OR REPLACE INTO rankings (keyword, position, clicks, impressions, ctr, date)
VALUES (?, ?, ?, ?, ?, ?)
""", (r["keyword"], r["position"], r["clicks"], r["impressions"], r["ctr"], r["date"]))
conn.commit()
conn.close()
Step 4: Detect changes
def detect_changes(rankings):
"""Detect significant ranking changes."""
conn = sqlite3.connect("rankings.db")
changes = []
for r in rankings:
prev = conn.execute("""
SELECT position FROM rankings
WHERE keyword = ? AND date < ?
ORDER BY date DESC LIMIT 1
""", (r["keyword"], r["date"])).fetchone()
if prev:
change = r["position"] - prev[0]
if abs(change) >= 3:
changes.append({
"keyword": r["keyword"],
"old_pos": prev[0],
"new_pos": r["position"],
"change": change,
"direction": "improved" if change < 0 else "dropped",
})
conn.close()
return changes
Step 5: Send alerts
import resend, os
resend.api_key = os.environ["RESEND_API_KEY"]
def send_ranking_alert(changes):
if not changes:
return
body = "<h3>Ranking Changes Detected</h3><ul>"
for c in changes:
body += f"<li><strong>{c['keyword']}:</strong> {c['old_pos']} → {c['new_pos']} ({c['direction']})</li>"
body += "</ul>"
resend.Emails.send({
"from": "SEO Alerts <[email protected]>",
"to": [os.environ["YOUR_EMAIL"]],
"subject": f"Ranking Alert: {len(changes)} changes detected",
"html": body,
})
print(f"Alert sent for {len(changes)} ranking changes")
Step 6: Automate with cron
# Check rankings daily at 9 AM
0 9 * * * cd /path/to/project && python track_rankings.py
Step 7: Streamlit dashboard
import streamlit as st
import pandas as pd
import plotly.express as px
import sqlite3
st.title("Keyword Ranking Tracker")
conn = sqlite3.connect("rankings.db")
df = pd.read_sql("SELECT * FROM rankings ORDER BY date DESC", conn)
# Latest rankings
st.subheader("Latest Rankings")
latest = df.drop_duplicates(subset=["keyword"], keep="first")
st.dataframe(latest[["keyword", "position", "clicks", "impressions", "date"]], use_container_width=True)
# Position trend
st.subheader("Position Trend")
selected_kw = st.selectbox("Keyword", df["keyword"].unique())
history = df[df["keyword"] == selected_kw].sort_values("date")
fig = px.line(history, x="date", y="position", title=f"Position: {selected_kw}",
labels={"position": "Position (lower is better)"})
fig.update_yaxes(autorange="reversed")
st.plotly_chart(fig, use_container_width=True)
# Top keywords by clicks
st.subheader("Top 10 by Clicks")
top = latest.nlargest(10, "clicks")
st.bar_chart(top.set_index("keyword")["clicks"])
Free vs paid rank trackers
| Tool | Price | Features | Best for |
|---|---|---|---|
| This script | Free | Daily checks, alerts, dashboard | Solo freelancers, small sites |
| Google Search Console | Free | Average position, clicks, impressions | Basic tracking |
| Ubersuggest | Free tier (3/day) | Volume, competition, position | Beginners |
| SERPWatcher | $30/mo | Daily tracking, alerts | Small businesses |
| Ahrefs | $99/mo | Comprehensive SEO suite | Agencies, enterprises |
| SEMrush | $120/mo | Comprehensive SEO suite | Agencies, enterprises |
Rule: Start with this free script. Upgrade to paid tools when you need more features or manage multiple sites.
Common mistakes
- Checking rankings daily — rankings fluctuate. Check weekly or monthly for trends.
- Ignoring impressions — high impressions + low clicks = title/meta description problem.
- Not tracking the right keywords — track keywords that drive traffic, not vanity keywords.
- Not comparing to competitors — track competitor rankings too.
- Overreacting to fluctuations — a drop from #3 to #5 is normal. A drop from #3 to #15 is a problem.
Key Concepts
- Google Search Console = free tool for search performance data
- Keyword ranking = position in search results (1 = top)
- Impressions = how many times your result appeared in search
- CTR = click-through rate (clicks / impressions)
- Average position = mean position across all impressions
- Ranking fluctuation = normal daily/weekly position changes
What to Try Next
- Automate SEO reports for clients
- Monitor competitor prices automatically
- Build an SEO dashboard in Streamlit
- Local SEO checklist for small businesses
FAQ
Google Search Console vs paid rank trackers — which is better?
GSC is free and shows real data (actual impressions, clicks, positions). Paid tools (Ahrefs, SEMrush) show estimated data and offer more features (competitor analysis, backlink tracking). Start with GSC; upgrade when you need more.
How often should I check rankings?
Weekly for tracking trends. Daily is too noisy (rankings fluctuate). Monthly for reporting to clients. Set up automated alerts for significant changes (3+ positions).
Can I track rankings for specific locations?
GSC shows average position across all locations. For location-specific tracking, use a tool like BrightLocal or Local Falcon (paid). Or manually check from different locations (see Check Google Maps Ranking).
What’s a good ranking to aim for?
Top 3 (first page, above the fold) for your primary keywords. Top 10 (first page) for secondary keywords. Anything below page 1 gets almost no clicks. Focus on moving page-2 keywords (positions 11-20) to page 1. See Rank Higher on Google Maps. See Automate SEO Reports. See Monitor Competitor Prices.