Download
Download rank-ai-tracker.zip (7 KB). It contains the Python script, this guide as a README, and example keywords.txt and prompts.txt files. Free to use, copy and change, with no sign-up.
Quick overview
This script takes one snapshot a week of where a brand stands in Google and in AI assistants, and keeps every snapshot so you can see the trend. For each keyword it records the position in the live top 100, the page that ranks, the three domains above everyone else, and whether an AI Overview or a local pack is showing and whether the brand appears in it. For each customer question it asks ChatGPT, Perplexity, Gemini or Claude and records whether the answer names the brand and whether it cites one of the brand’s pages. Each run is a single command and writes a dated folder plus a line in a history file.
Who it’s built for
Agencies and in-house SEOs who report on rankings and are now being asked about AI search as well. It suits a small brand that wants to know if it shows up at all, and an agency running the same check across clients. We run it every week on our own site at Digital Royalty, a UK web and software studio, and this is that script with our names taken out.
What you get
serp-summary.csvwith one row per keyword: position, ranking URL, top three domains, AI Overview shown and whether it mentions you, local pack shown and whether you’re in it, and the other SERP features on the page.llm-summary.csvwith one row per question per assistant: named or not, cited or not, which of your URLs were cited, and how many sources the answer used.- Every raw API response saved as JSON. When a new question comes up in three months you can answer it from the files you already have instead of paying for the data again.
history.csv, which gains one line per run with the headline counts (keywords ranked, top 10, AI Overviews mentioning you, answers naming you, answers citing you, cost). Rankings and AI answers can’t be backfilled, so a week you miss is gone for good.
What you need to get started
- A DataForSEO account and your API login and password (from the dashboard, not the account password).
- Python 3.9 or later, with
requestsinstalled. - A keyword list (
keywords.txt) and a list of questions a customer would put to an assistant (prompts.txt). Both files ship with examples. - The brand name, its domain, and any other spellings people use.
Workflow breakdown
- Put your keywords in
keywords.txtand your customer questions inprompts.txt. Keep both stable from week to week. Add to them, but don’t rename or delete lines, or the history stops lining up. - Set
DATAFORSEO_LOGINandDATAFORSEO_PASSWORDin your environment. - Run it with your brand and domain, for example
python rank_ai_tracker.py --brand "Acme Plumbing" --domain acmeplumbing.co.uk --web-search. Add--alias "acme plumbing ltd"for other spellings,--platforms chatgpt,perplexity,gemini,claudeto choose assistants, and--location-code/--languagefor markets outside the UK. - For each keyword the script calls the SERP API (Google Organic, live, depth 100) and checks the result for your domain, AI Overview items and local pack items.
- For each question and assistant it calls the AI Optimization API (LLM Responses, live) and checks the answer text for your brand and the cited URLs for your domain.
- It writes the dated folder, appends to
history.csv, and prints what the run cost. - Schedule it weekly (cron, Task Scheduler, or an n8n Execute Command node) and read the trend once a month. Single weeks move around a lot, so judge a change after it has held for three or four runs.
Cost
A Google SERP at depth 100 costs about $0.013 and an assistant answer costs a fraction of a cent. Thirty keywords and ten questions on two assistants come to roughly $0.50 a run. Our test run of one keyword and one question cost $0.02.
Notes from running it
- Brand matching is a text match on the raw response, so it survives changes to the API’s item structure. The flip side is that a brand name which is also a common word will over-count. Use the domain and a distinctive alias in that case.
- The SERP API sometimes returns a transient error for one keyword. The run carries on, lists the failures in
failed.txt, and you retry them next week. - If an assistant’s default model is retired,
python rank_ai_tracker.py --list-models chatgptshows what the API accepts now, and you change the default at the top of the script.
Where to go next
If the AI answers aren’t naming you, the AEO Content Scorer checks how easily an assistant can lift an answer from a page, and the rest of the free SEO tools cover the on-page side. More templates, checklists and SOP packs are in the resource library. If you’d rather have the tracking set up and read for you, get in touch.