<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Build a Simple AI Visibility Tracker in Python: Is ChatGPT-Style Search Mentioning Your Brand?]]></title><description><![CDATA[About 60 lines of Python to check whether AI answer engines mention your brand and cite your site.]]></description><link>https://blazlyai.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 12:18:39 GMT</lastBuildDate><atom:link href="https://blazlyai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Build a Simple AI Visibility Tracker in Python: Is ChatGPT-Style Search Mentioning Your Brand?]]></title><description><![CDATA[About 60 lines of Python to check whether AI answer engines mention your brand and cite your site.]]></description><link>https://blazlyai.hashnode.dev/build-a-simple-ai-visibility-tracker-in-python-is-chatgpt-style-search-mentioning-your-brand</link><guid isPermaLink="true">https://blazlyai.hashnode.dev/build-a-simple-ai-visibility-tracker-in-python-is-chatgpt-style-search-mentioning-your-brand</guid><category><![CDATA[geo]]></category><category><![CDATA[SEO]]></category><category><![CDATA[ai-visibility]]></category><dc:creator><![CDATA[Jerryton Surya]]></dc:creator><pubDate>Tue, 17 Nov 2026 10:02:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afc24d3f9e3db896a8a3217/9789f40d-9ba4-49ca-8e8a-ff2be26dfa6b.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When someone asks an AI engine "what's the best tool for X?", does your product show up? And if it does, does the engine link to your site, or to a competitor's comparison page?</p>
<p>Google Search Console can't tell you that. Most teams only find out by manually typing questions into ChatGPT or Perplexity, which doesn't scale and leaves no history.</p>
<p>In this post, we'll build a small Python script that:</p>
<ol>
<li>Runs a list of buyer-style prompts through an AI search API</li>
<li>Checks whether your brand (and your competitors) are mentioned</li>
<li>Checks whether your domain is among the cited sources</li>
<li>Logs everything to a CSV so you can track changes over time</li>
</ol>
<h2>Why this matters</h2>
<p>AI answers are taking clicks away from search results. Pew Research found users clicked a traditional search result in about 8% of visits that showed an AI summary, versus 15% without one. If you're not in the answer, you're increasingly not in the conversation.</p>
<p>The practice of optimizing for this is called <strong>generative engine optimization (GEO)</strong>, and the first step is simply measuring where you stand.</p>
<h2>Setup</h2>
<p>We'll use Perplexity's API because it's an AI <em>search</em> engine and returns the sources it cited, which is exactly what we want to track. Its API is OpenAI-compatible, so we can use the <code>openai</code> package.</p>
<pre><code class="language-bash">pip install openai
export PERPLEXITY_API_KEY="your-key-here"
</code></pre>
<blockquote>
<p>Model names change often. Check Perplexity's API docs for the current search model name before running this.</p>
</blockquote>
<h2>Define your brand and prompts</h2>
<p>The prompts are the most important part. Write the questions your real customers would ask, not keywords:</p>
<pre><code class="language-python">BRAND = "Acme"
BRAND_DOMAIN = "acme.com"
COMPETITORS = ["CompetitorOne", "CompetitorTwo", "CompetitorThree"]

PROMPTS = [
    "What are the best tools for tracking brand visibility in AI search?",
    "Which AI visibility tool is best for a small marketing team?",
    "Alternatives to CompetitorOne for monitoring ChatGPT mentions",
    "How can I see if Perplexity cites my website?",
]
</code></pre>
<h2>Query the engine</h2>
<pre><code class="language-python">import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PERPLEXITY_API_KEY"],
    base_url="https://api.perplexity.ai",
)

def ask(prompt: str) -&gt; tuple[str, list[str]]:
    resp = client.chat.completions.create(
        model="sonar",  # check the docs for the current model name
        messages=[{"role": "user", "content": prompt}],
    )
    answer = resp.choices[0].message.content or ""
    # Perplexity returns cited URLs as an extra field on the response
    citations = getattr(resp, "citations", None) or []
    return answer, citations
</code></pre>
<h2>Detect mentions and citations</h2>
<p>A plain substring check gives false positives ("Acme" matching "Acmeville"), so use word boundaries:</p>
<pre><code class="language-python">import re

def mentioned(text: str, name: str) -&gt; bool:
    return re.search(rf"\b{re.escape(name)}\b", text, re.IGNORECASE) is not None

def cited(citations: list[str], domain: str) -&gt; bool:
    return any(domain in url for url in citations)
</code></pre>
<h2>Run it and log to CSV</h2>
<pre><code class="language-python">import csv
import datetime
from pathlib import Path

LOG_FILE = Path("ai_visibility_log.csv")
FIELDS = ["date", "prompt", "brand_mentioned", "brand_cited", "competitors_mentioned", "top_sources"]

def run():
    today = datetime.date.today().isoformat()
    new_file = not LOG_FILE.exists()

    with LOG_FILE.open("a", newline="", encoding="utf-8") as f:
        writer = csv.DictWriter(f, fieldnames=FIELDS)
        if new_file:
            writer.writeheader()

        for prompt in PROMPTS:
            answer, citations = ask(prompt)
            row = {
                "date": today,
                "prompt": prompt,
                "brand_mentioned": mentioned(answer, BRAND),
                "brand_cited": cited(citations, BRAND_DOMAIN),
                "competitors_mentioned": ", ".join(c for c in COMPETITORS if mentioned(answer, c)),
                "top_sources": " | ".join(citations[:5]),
            }
            writer.writerow(row)
            status = "✅" if row["brand_mentioned"] else "❌"
            print(f"{status} {prompt[:60]}")

if __name__ == "__main__":
    run()
</code></pre>
<p>Run it weekly with cron (or a GitHub Action) and you'll build a history of your AI visibility:</p>
<pre><code class="language-bash">0 9 * * 1 cd /path/to/project &amp;&amp; python tracker.py
</code></pre>
<h2>Read the results</h2>
<p>After a few runs, two numbers are worth watching:</p>
<ul>
<li><strong>Mention rate:</strong> % of prompts where your brand appears in the answer</li>
<li><strong>Citation rate:</strong> % of prompts where your domain is a cited source</li>
</ul>
<p>The <code>top_sources</code> column is the most useful one in practice. It shows which pages the AI engine trusts for your topic. If the same review site or comparison article keeps showing up, getting your product covered <em>there</em> may do more than editing your own pages.</p>
<h2>Limitations (be honest with yourself)</h2>
<p>This script is a good start, but it has real gaps:</p>
<ul>
<li><strong>API ≠ the consumer app.</strong> Results from the API can differ from what users see in the app.</li>
<li><strong>Answers are non-deterministic.</strong> The same prompt can give different answers. Run each prompt several times and average the results.</li>
<li><strong>One engine only.</strong> Your customers also use ChatGPT, Gemini, Google AI Overviews, Claude and Copilot, and each behaves differently.</li>
<li><strong>Prompt coverage.</strong> Tracking 4 prompts is easy; tracking 200 across 6 engines gets expensive and fiddly fast.</li>
</ul>
<p>That's the point where dedicated GEO tools make sense. They handle multiple engines, repeated sampling, competitor benchmarking and reporting. If you're evaluating them, I wrote a detailed comparison covering pricing, engine coverage and team fit: <a href="https://www.blazly.ai/post/best-generative-engine-optimization-tools"><strong>11 Best Generative Engine Optimization Tools</strong></a></p>
<h2>Wrapping up</h2>
<p>You don't need a big budget to start measuring AI visibility. A list of good prompts, an API key and a CSV will tell you more than guessing. Once you know where you stand, you can work on the content and technical fixes that actually get you cited.</p>
<p>What would you add to this script? Sentiment analysis on how your brand is described is next on my list.</p>
<hr />
<p><em>Disclosure: I work at Blazly, one of the tools covered in the linked comparison.</em></p>
]]></content:encoded></item></channel></rss>