在 Google I/O 2026 之后,Google AI 模式现已拥有 1B+ 用户。当 AI 模式生成答案时,它可以引用您的网站或完全跳过它。本教程构建了一个跟踪器,用于监控您的品牌是否出现在目标关键字的 AI 模式响应中。每个关键字检查的费用为 0.005 美元。
前置条件
- Python 3.8+
- 请求库
- 来自 scavio.dev 的 Scavio API 密钥
- 要监控的目标关键字列表
操作指南
步骤 1: 检查 AI 模式信号的 SERP 结果
查询目标关键字并在响应中查找 AI 生成的内容。
Python
import os, requests, json
from datetime import datetime
API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
BRAND = 'Scavio'
KEYWORDS = [
'best search api for ai agents',
'how to add search to ai agent',
'mcp search tool',
'serp api alternative',
'web search api pricing',
]
def check_ai_mode(keyword, brand):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': keyword, 'country_code': 'us'}, timeout=10).json()
# Check AI overview / featured snippet
ai_overview = data.get('ai_overview', data.get('answer_box', {}))
organic = data.get('organic_results', [])
featured = data.get('featured_snippet', {})
brand_lower = brand.lower()
in_ai = brand_lower in json.dumps(ai_overview).lower() if ai_overview else False
in_featured = brand_lower in json.dumps(featured).lower() if featured else False
in_organic = any(brand_lower in json.dumps(r).lower() for r in organic[:10])
organic_pos = next((i+1 for i, r in enumerate(organic) if brand_lower in json.dumps(r).lower()), None)
return {
'keyword': keyword,
'in_ai_mode': in_ai,
'in_featured': in_featured,
'in_organic': in_organic,
'organic_position': organic_pos,
'has_ai_overview': bool(ai_overview),
}
print(f'Tracking AI Mode for "{BRAND}" across {len(KEYWORDS)} keywords\n')
results = []
for kw in KEYWORDS:
r = check_ai_mode(kw, BRAND)
results.append(r)
ai_status = 'CITED' if r['in_ai_mode'] else 'ABSENT'
org_status = f'#{r["organic_position"]}' if r['organic_position'] else 'absent'
print(f' {kw[:40]:40} | AI: {ai_status:6} | Organic: {org_status}')
print(f'\nCost: ${len(KEYWORDS) * 0.005:.3f}')步骤 2: 计算 AI 模式可见度分数
将结果汇总为可见度分数,显示 AI 模式引用您品牌的频率。
Python
def ai_mode_visibility(results, brand):
total = len(results)
ai_cited = sum(1 for r in results if r['in_ai_mode'])
featured = sum(1 for r in results if r['in_featured'])
organic = sum(1 for r in results if r['in_organic'])
has_ai = sum(1 for r in results if r['has_ai_overview'])
ai_score = (ai_cited / has_ai * 100) if has_ai else 0
overall_score = ((ai_cited * 3 + featured * 2 + organic) / (total * 3) * 100)
print(f'\n=== AI Mode Visibility: {brand} ===')
print(f' Keywords tracked: {total}')
print(f' AI Mode present: {has_ai}/{total} queries')
print(f' Brand in AI Mode: {ai_cited}/{has_ai} ({ai_score:.0f}%)')
print(f' Brand in Featured: {featured}/{total}')
print(f' Brand in Organic: {organic}/{total}')
print(f' Overall Visibility: {overall_score:.0f}/100')
# Gaps
gaps = [r['keyword'] for r in results if r['has_ai_overview'] and not r['in_ai_mode']]
if gaps:
print(f'\n AI Mode Gaps (present but not cited):')
for g in gaps:
print(f' - {g}')
return {'ai_score': ai_score, 'overall': overall_score, 'gaps': gaps}
visibility = ai_mode_visibility(results, BRAND)步骤 3: 存储每日快照以进行趋势跟踪
保存每日可见性数据并随时间进行比较,以检测 Google I/O 大会后的变化。
Python
def save_daily_snapshot(results, visibility, output_file='ai_mode_tracking.json'):
try:
with open(output_file) as f:
history = json.load(f)
except FileNotFoundError:
history = []
snapshot = {
'date': datetime.now().strftime('%Y-%m-%d'),
'ai_score': visibility['ai_score'],
'overall_score': visibility['overall'],
'keywords_tracked': len(results),
'ai_cited': sum(1 for r in results if r['in_ai_mode']),
'details': results,
}
history.append(snapshot)
with open(output_file, 'w') as f:
json.dump(history, f, indent=2)
# Trend analysis
print(f'\n=== Trend ===')
if len(history) >= 2:
prev = history[-2]
delta = snapshot['ai_score'] - prev['ai_score']
direction = 'UP' if delta > 0 else 'DOWN' if delta < 0 else 'STABLE'
print(f' AI Score: {prev["ai_score"]:.0f} -> {snapshot["ai_score"]:.0f} ({direction} {abs(delta):.0f}pt)')
print(f' AI Citations: {prev["ai_cited"]} -> {snapshot["ai_cited"]}')
else:
print(f' First snapshot saved. Run daily to track trends.')
print(f'\n Daily cost: ${len(results) * 0.005:.3f}')
print(f' Monthly cost: ${len(results) * 0.005 * 30:.2f}')
save_daily_snapshot(results, visibility)Python 示例
Python
import os, requests, json
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}
def check_ai_mode(keyword, brand):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': keyword, 'country_code': 'us'}, timeout=10).json()
ai = data.get('ai_overview', data.get('answer_box', {}))
cited = brand.lower() in json.dumps(ai).lower() if ai else False
print(f'{keyword[:40]:40} | AI cited: {cited}')
check_ai_mode('best search api for agents', 'Scavio')JavaScript 示例
JavaScript
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: SH,
body: JSON.stringify({ query: 'best search api for agents', country_code: 'us' })
}).then(r => r.json());
const ai = data.ai_overview || data.answer_box || {};
const cited = JSON.stringify(ai).toLowerCase().includes('scavio');
console.log(`AI Mode cited: ${cited}`);预期输出
JSON
Tracking AI Mode for "Scavio" across 5 keywords
best search api for ai agents | AI: CITED | Organic: #3
how to add search to ai agent | AI: ABSENT | Organic: #5
mcp search tool | AI: CITED | Organic: #2
serp api alternative | AI: ABSENT | Organic: #4
web search api pricing | AI: ABSENT | Organic: #7
Cost: $0.025
=== AI Mode Visibility: Scavio ===
Keywords tracked: 5
AI Mode present: 4/5 queries
Brand in AI Mode: 2/4 (50%)
Overall Visibility: 53/100
Daily cost: $0.025
Monthly cost: $0.75