Build a rank tracker with a Google SERP API
A rank tracker searches each of your keywords on Google on a schedule, finds the position of your domain in the results, and stores it with the date. With BestSERP each keyword costs one credit per page of 10 results checked, so tracking 100 keywords in the top 20 every day costs about $3 a month.
Last updated:
Key takeaways
- 100 keywords, top 10, daily: 3,000 credits, about $1.50 a month.
- 100 keywords, top 20, daily: 6,000 credits, about $3.00 a month.
- Built on the Google Search API and the Google Maps API.
- A complete Python example is below: set BESTSERP_API_KEY and run it.
The problem
Search Console reports average positions with a delay and only for your own site. To see today's ranking for a keyword, in a given country, for your site and your competitors, you need the results page itself.
Checking pages by hand does not scale past a few keywords, and scraping Google yourself means maintaining browsers, proxies and parsers. A SERP API returns the ranked results as JSON, so the tracker is a loop and a database table.
Suggested architecture
- 1
Keyword list
Store each keyword with its country (gl), language (hl) and the domain to look for. Group keywords by project.
- 2
Scheduler
A cron job or a queue runs the check once a day. Spread requests to stay under 60 searches per minute, or ask for a higher limit.
- 3
Search and match
Call /search with num 20 (two pages, 2 credits) or num 10 (1 credit). Walk organic[] and match the domain field against your domain and its subdomains.
- 4
History
Insert one row per keyword and day: date, position (or empty when not found), URL that ranked. Charts and alerts read from this table.
Complete example
BESTSERP_API_KEY and run it with Python 3.9+ and requests.import os
import time
import requests
API = "https://api.bestserp.com"
HEADERS = {"X-API-KEY": os.environ["BESTSERP_API_KEY"]}
def search(endpoint: str, **body) -> dict:
"""POST one search and return the JSON. Polls while the API answers 202 (still running)."""
r = requests.post(f"{API}/{endpoint}", headers=HEADERS, json={"timeout": 120, **body}, timeout=130)
while r.status_code == 202:
time.sleep(2)
r = requests.get(f"{API}/requests/{r.json()['requestId']}", headers=HEADERS, timeout=30)
r.raise_for_status()
return r.json()
import csv
import datetime
DOMAIN = "example.com"
KEYWORDS = ["running shoes", "trail running shoes", "best marathon shoes"]
COUNTRY, LANGUAGE = "us", "en"
def find_rank(keyword: str):
results = search("search", q=keyword, gl=COUNTRY, hl=LANGUAGE, num=20) # top 20 = 2 credits
for item in results.get("organic", []):
domain = item.get("domain", "")
if domain == DOMAIN or domain.endswith("." + DOMAIN):
return item["position"], item["link"]
return None, None
with open("ranks.csv", "a", newline="") as f:
out = csv.writer(f)
for keyword in KEYWORDS:
position, url = find_rank(keyword)
out.writerow([datetime.date.today().isoformat(), keyword, COUNTRY, position or "", url or ""])
print(keyword, position or "not in top 20")
time.sleep(1) # stay well under 60 searches per minuteWhat it costs
| Scenario | Credits per month | Cost per month |
|---|---|---|
| 100 keywords, top 10, daily | 3,000 | $1.50 |
| 100 keywords, top 20, daily | 6,000 | $3.00 |
| 1,000 keywords, top 10, daily | 30,000 | $15.00 |
| 1,000 keywords, top 50, weekly | 20,000 | $10.00 |
Frequently asked questions
How do I track rankings in several countries?
Should I check the top 10 or the top 100?
Why does my position differ from what I see in my browser?
Can I track local rankings on Google Maps?
Are failed checks charged?
Start with 3,000 free searches
No credit card. Sign in with Google, create a key, send your first request.