DEV Community

CiteProof
CiteProof

Posted on Edited on

Build an AI citation map from a CSV in 30 lines of Python

If you're tracking which sources ChatGPT, Perplexity or Gemini cite for a set of questions, you quickly end up with a messy spreadsheet. A small script turns it into the useful view: which domains get cited most, by which engine, and on how many distinct questions.

The input

One row per cited URL. Collect it manually or with whatever tool you use:

question,engine,cited_url
best invoicing app for freelancers,chatgpt,https://www.g2.com/categories/invoicing
best invoicing app for freelancers,perplexity,https://www.reddit.com/r/freelance/comments/abc
best invoicing app for freelancers,gemini,https://zapier.com/blog/best-invoicing-software/
Enter fullscreen mode Exit fullscreen mode

The script

import csv
import sys
from collections import Counter, defaultdict
from urllib.parse import urlparse

def domain(url):
    host = urlparse(url).netloc.lower()
    return host[4:] if host.startswith("www.") else host

counts = Counter()
by_engine = defaultdict(Counter)
questions = defaultdict(set)

with open(sys.argv[1], newline="", encoding="utf-8") as f:
    for row in csv.DictReader(f):
        d = domain(row["cited_url"])
        counts[d] += 1
        by_engine[row["engine"]][d] += 1
        questions[d].add(row["question"])

print(f"{'domain':35} {'cites':>5} {'questions':>9}  engines")
for d, n in counts.most_common(25):
    engines = ", ".join(e for e in by_engine if by_engine[e][d])
    print(f"{d:35} {n:>5} {len(questions[d]):>9}  {engines}")
Enter fullscreen mode Exit fullscreen mode

Run it with python citation_map.py citations.csv.

Reading the output

  • "questions" matters more than "cites". A domain cited 10 times for one question is less useful to you than one cited once on each of 8 questions.
  • Domains cited by all engines are the safest targets. Ones cited by a single engine may come and go.
  • Group domains by type (directory, review site, publisher, forum, competitor). Each type needs a different action: a listing, a pitch, a useful answer, or better content on your own page.

Caveats

AI answers vary from run to run and by location, and engines don't always show every source they used. Treat the map as a sample, re-run it monthly with the same questions, and compare like with like.

To collect the input faster, CiteProof's free AI citation checker queries ChatGPT, Perplexity and Gemini with a question and lists the domains each one cites (2 free checks a day, no signup).

Disclosure: I'm the founder of CiteProof.

Top comments (0)