DEV Community

VaiSoft
VaiSoft

Posted on Fully Autonomous

Build a Tiny AI-Visibility Tracker for a Local Business in Python

Local business owners keep hearing that they need to "show up in ChatGPT." Agencies sell reports on it, and software vendors sell dashboards. If you build sites for small clients, you can put together a basic version yourself in about 80 lines of Python.

It will not replace a full tool, but it answers the question owners actually ask: when someone asks an AI assistant for a business like mine, does it name me, and is that getting better?

The idea: same questions, every month

The single most important rule is to keep the question set fixed. If the questions change each month, you cannot compare results. Write 10 to 20 questions a real customer would type, in their words, with the town in them:

# questions.txt
who is the best emergency plumber in Pittsford NY
plumber near Perinton NY that works weekends
how much does water heater replacement cost in Pittsford NY
recommend a licensed plumber in Brighton NY
who fixes sewer backups in Monroe County NY
Enter fullscreen mode Exit fullscreen mode

Then list the business and its main competitors, with the name variations people and models use:

# brands.py
BRANDS = {
    "Example Plumbing": ["example plumbing", "example plumbing co"],
    "Rival One": ["rival one", "rival one plumbing"],
    "Rival Two": ["rival two", "rivaltwo"],
}
Enter fullscreen mode Exit fullscreen mode

Asking the model

Here is a version using the OpenAI Python SDK. Any provider works; you only need a function that takes a question and returns text.

# ask.py
import os
from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from the environment
MODEL = os.environ.get("TRACKER_MODEL", "gpt-4.1-mini")

def ask(question: str) -> str:
    resp = client.responses.create(model=MODEL, input=question)
    return resp.output_text
Enter fullscreen mode Exit fullscreen mode

One honest caveat: an API call is not the same as the ChatGPT app with web search turned on, and neither is the same as Google AI Overviews. Treat this as one consistent signal, not the full picture. What matters is that you measure the same way every time.

Logging and scoring

# track.py
import csv, datetime, pathlib, re
from ask import ask
from brands import BRANDS

QUESTIONS = [q.strip() for q in open("questions.txt") if q.strip() and not q.startswith("#")]
RUNS_PER_QUESTION = 3  # answers vary, so sample more than once
LOG = pathlib.Path("ai_visibility_log.csv")

def mentioned(answer: str, variants: list[str]) -> bool:
    text = answer.lower()
    return any(re.search(r"\b" + re.escape(v) + r"\b", text) for v in variants)

def main():
    today = datetime.date.today().isoformat()
    new_file = not LOG.exists()
    with LOG.open("a", newline="", encoding="utf-8") as f:
        w = csv.writer(f)
        if new_file:
            w.writerow(["date", "question", "run", "brand", "mentioned"])
        for q in QUESTIONS:
            for run in range(RUNS_PER_QUESTION):
                answer = ask(q)
                for brand, variants in BRANDS.items():
                    w.writerow([today, q, run, brand, int(mentioned(answer, variants))])
    print(f"Logged {len(QUESTIONS) * RUNS_PER_QUESTION} answers for {today}")

if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

Running each question three times matters. The same prompt can name a business in one answer and skip it in the next, so a single run gives you noise.

Two numbers worth reporting

# report.py
import pandas as pd

df = pd.read_csv("ai_visibility_log.csv")

# Mention rate: share of answers that name each brand, per month
df["month"] = df["date"].str[:7]
rate = df.groupby(["month", "brand"])["mentioned"].mean().unstack().round(2)
print("Mention rate\n", rate, "\n")

# Share of voice: each brand's mentions as a share of all brand mentions
counts = df[df["mentioned"] == 1].groupby(["month", "brand"]).size().unstack(fill_value=0)
sov = counts.div(counts.sum(axis=1), axis=0).round(2)
print("Share of voice\n", sov)
Enter fullscreen mode Exit fullscreen mode

Mention rate answers "how often are we named?" If the business appears in 6 of 30 answers, that is 0.20.

Share of voice answers "how do we compare?" If the business is named 6 times and two rivals are named 9 and 15 times, the business holds 0.20 of the conversation and the leading rival holds 0.50.

A third check is worth doing by hand: read a sample of the answers that do mention the business and confirm the facts are right. Wrong hours, an old address or a service the business dropped years ago usually trace back to an outdated directory listing or an old page.

Why bother

Use of ChatGPT and other AI tools for local business recommendations jumped from 6% to 45% in one year (BrightLocal, 2026). Owners are going to ask about it, and a simple, repeatable measurement beats guessing.

It also helps when a client is comparing agencies. A proposal that never lists the questions it will test, or changes them every month, is a warning sign, and now you can explain why.

Ideas to extend it

  • Run it on a schedule (cron or a GitHub Action) on the same day each month
  • Add a second provider behind the same ask() interface and compare
  • Save the raw answers so you can look for repeated wrong facts
  • Flag questions where no local business is named at all, since those are the easiest gaps to close with better content

If you want the business-side view of what an AI SEO proposal should include, such as the question set, deliverables, reporting and contract terms, Vaisoft wrote a checklist for owners reviewing one: https://www.vaisoft.net/blog/ai-seo-agency-pittsford-ny

Top comments (2)

Collapse
 
alicexixi85 profile image
Dejun (Alice) Chen •

One thing that will bite the month-over-month comparison: without web search, gpt-4.1-mini answers from its training data, so nothing the business does this month can move that number. What will move it is the provider updating the model behind the alias. I'd log resp.model on every row and pin a dated snapshot, so a jump in the chart can be traced to the model instead of being read as a win or a loss.

Then, if the owner's question is "is this getting better?", run a second series with the provider's web search tool turned on, since that's the only version that can see a new page or a fixed directory listing.

Collapse
 
zarko_zivkovic_1c91189c35 profile image
Zarko Zivkovic •

I like the idea of keeping the tracking infrastructure simple. You don't necessarily need an expensive platform to establish an initial visibility baseline for a local business.

I'd extend the script to repeat each prompt several times, preserve the raw responses and distinguish between mentions, recommendations and citations.

For local businesses, I'd also record geographic context and language separately. Asking about a business in English and asking the same question in the local language can produce very different results.

Collecting the data is relatively straightforward. Making sure it supports reliable conclusions is the harder part.