Prompts where a competitor beats you
Find the prompts where AI answers name a competitor more often than your brand.
The brands report with the prompt dimension gives 1 row for each brand and prompt. This script asks for your rows and the rows of 1 competitor, and prints the prompts where the competitor has the higher visibility.
import os
import requests
API = "https://api.lumirank.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['LUMIRANK_API_KEY']}"}
def get(path, **params):
resp = requests.get(f"{API}{path}", headers=HEADERS, params=params, timeout=60)
resp.raise_for_status()
return resp.json()
me = get("/brand")["competitor_id"]
rival = get("/competitors", status="tracked")["data"][0]
rows = get("/reports/brands", dimensions="prompt", competitor_id=f"{me},{rival['id']}", limit=10000)["data"]
pairs = {}
for row in rows:
pairs.setdefault(row["prompt_id"], {})["me" if row["is_self"] else "rival"] = row
for pair in sorted(pairs.values(), key=lambda p: p["me"]["visibility"] - p["rival"]["visibility"]):
gap = pair["rival"]["visibility"] - pair["me"]["visibility"]
if gap > 0:
print(f"{gap:+.0%} {rival['name']} beats you on: {pair['me']['prompt_text']}")Every prompt with answers has a row for every brand in the report, so each prompt has both rows. competitor_id only chooses which rows come back after the numbers are calculated, so share_of_voice still divides by all tracked brands.
The script uses the 1st competitor you track. To compare with another one, find its id by name in /v1/competitors?status=tracked.