google-meta-ads-ga4-mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoogle Ads + Meta Ads + GA4 MCP Server
Google Ads + Meta Ads + GA4 MCP Server
Overview
概述
The Google Ads + Meta Ads + GA4 MCP server is a unified Model Context Protocol server that provides 250+ tools for managing advertising campaigns and analytics across Google Ads, Meta (Facebook/Instagram) Ads, and Google Analytics 4. It enables AI assistants like Claude, ChatGPT, Cursor, and n8n to perform full read-write operations on these platforms.
Key capabilities:
- 150+ Google Ads tools — Campaign CRUD, keyword research, bidding, ad creation, audiences, extensions, experiments
- 80+ Meta Ads tools — Campaign/ad set/creative management, audience targeting, lead gen, product catalogs
- 20+ GA4 tools — Reporting, audience analysis, property config, attribution, key events
- Cross-platform analytics — Unified ROAS, performance comparison, budget allocation
This is a remote MCP server (hosted), not a local installation. You connect via URL endpoint.
Google Ads + Meta Ads + GA4 MCP服务器是一个统一的Model Context Protocol服务器,提供250+工具用于跨Google Ads、Meta(Facebook/Instagram)Ads和Google Analytics 4管理广告营销活动与分析。它支持Claude、ChatGPT、Cursor和n8n等AI助手对这些平台执行完整的读写操作。
核心功能:
- 150+ Google Ads工具——营销活动增删改查(CRUD)、关键词研究、出价管理、广告创建、受众管理、广告附加信息、实验管理
- 80+ Meta Ads工具——营销活动/广告组/创意管理、受众定向、线索生成、产品目录管理
- 20+ GA4工具——报告生成、受众分析、属性配置、归因分析、关键事件追踪
- 跨平台分析——统一ROAS(广告支出回报率)、表现对比、预算分配
这是一个远程MCP服务器(托管式),而非本地安装版本。您通过URL端点进行连接。
Installation & Setup
安装与设置
Claude Desktop
Claude Desktop
-
Locate your Claude config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add the server configuration:
json
{
"mcpServers": {
"google-meta-ads-ga4": {
"url": "YOUR_MCP_ENDPOINT_URL"
}
}
}- Restart Claude Desktop
- Look for the MCP connection indicator (🔌) in the bottom-right corner
-
找到您的Claude配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
添加服务器配置:
json
{
"mcpServers": {
"google-meta-ads-ga4": {
"url": "YOUR_MCP_ENDPOINT_URL"
}
}
}- 重启Claude Desktop
- 查看右下角的MCP连接指示器(🔌)
ChatGPT
ChatGPT
- Navigate to Settings → Connectors → Add custom connector
- Enter:
- Name:
Google Meta Ads GA4 - URL:
YOUR_MCP_ENDPOINT_URL
- Name:
- Click Save
- The connector will appear in your available tools
- 导航至设置 → 连接器 → 添加自定义连接器
- 输入:
- 名称:
Google Meta Ads GA4 - URL:
YOUR_MCP_ENDPOINT_URL
- 名称:
- 点击保存
- 该连接器将出现在您的可用工具列表中
Cursor
Cursor
- Open
~/.cursor/mcp.json - Add:
json
{
"mcpServers": {
"google-meta-ads-ga4": {
"url": "YOUR_MCP_ENDPOINT_URL"
}
}
}- Restart Cursor
- 打开
~/.cursor/mcp.json - 添加:
json
{
"mcpServers": {
"google-meta-ads-ga4": {
"url": "YOUR_MCP_ENDPOINT_URL"
}
}
}- 重启Cursor
Windsurf
Windsurf
- Open
~/.codeium/windsurf/mcp_config.json - Add the same configuration as Cursor
- Restart Windsurf
- 打开
~/.codeium/windsurf/mcp_config.json - 添加与Cursor相同的配置
- 重启Windsurf
Claude Code (CLI)
Claude Code(CLI)
bash
claude mcp add google-meta-ads-ga4 --transport sse YOUR_MCP_ENDPOINT_URLbash
claude mcp add google-meta-ads-ga4 --transport sse YOUR_MCP_ENDPOINT_URLn8n
n8n
- Add an MCP Client node to your workflow
- Configure:
- Server URL:
YOUR_MCP_ENDPOINT_URL - Transport: SSE (Server-Sent Events)
- Authentication: Bearer token (recommended)
- Server URL:
Import the pre-built workflow template to get started.
- 在您的工作流中添加MCP Client节点
- 配置:
- 服务器URL:
YOUR_MCP_ENDPOINT_URL - 传输方式:SSE(Server-Sent Events)
- 认证:Bearer令牌(推荐)
- 服务器URL:
导入预构建工作流模板快速开始。
Codex CLI
Codex CLI
Add to :
~/.codex/config.tomltoml
[mcp.google-meta-ads-ga4]
url = "YOUR_MCP_ENDPOINT_URL"
transport = "sse"添加至:
~/.codex/config.tomltoml
[mcp.google-meta-ads-ga4]
url = "YOUR_MCP_ENDPOINT_URL"
transport = "sse"Authentication & Credentials
认证与凭据
This server uses OAuth 2.1 with PKCE for secure authentication. The authentication flow is handled by the hosted MCP server — you don't manage API keys locally.
First-time setup:
- When you first use a tool, you'll be prompted to authenticate
- Follow the OAuth flow for the specific platform (Google Ads, Meta, or GA4)
- Grant the required permissions
- Credentials are securely stored on the server side
Environment variables (if self-hosting):
- — Google Ads API developer token
GOOGLE_ADS_DEVELOPER_TOKEN - — OAuth client ID
GOOGLE_ADS_CLIENT_ID - — OAuth client secret
GOOGLE_ADS_CLIENT_SECRET - — Meta app ID
META_APP_ID - — Meta app secret
META_APP_SECRET - — GA4 property ID
GA4_PROPERTY_ID
本服务器使用OAuth 2.1 with PKCE进行安全认证。认证流程由托管的MCP服务器处理——您无需在本地管理API密钥。
首次设置:
- 首次使用工具时,系统会提示您进行认证
- 遵循对应平台(Google Ads、Meta或GA4)的OAuth流程
- 授予所需权限
- 凭据将安全存储在服务器端
环境变量(若自行托管):
- — Google Ads API开发者令牌
GOOGLE_ADS_DEVELOPER_TOKEN - — OAuth客户端ID
GOOGLE_ADS_CLIENT_ID - — OAuth客户端密钥
GOOGLE_ADS_CLIENT_SECRET - — Meta应用ID
META_APP_ID - — Meta应用密钥
META_APP_SECRET - — GA4属性ID
GA4_PROPERTY_ID
Google Ads Tools
Google Ads工具
List All Campaigns
列出所有营销活动
javascript
// Tool: list_campaigns
// Lists all campaigns with performance metrics
const campaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_30_DAYS"
});
// Response includes: campaign name, status, budget, impressions, clicks, cost, conversions, ROASjavascript
// Tool: list_campaigns
// 列出带有绩效指标的所有营销活动
const campaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_30_DAYS"
});
// 返回内容包括:营销活动名称、状态、预算、展示量、点击量、花费、转化量、ROASCreate a Search Campaign
创建搜索营销活动
javascript
// Tool: create_search_campaign
// Creates a new Google Search campaign
const campaign = await mcp.call_tool("create_search_campaign", {
customer_id: "1234567890",
campaign_name: "Q2 2026 CRM Software Campaign",
budget_amount_micros: 50000000, // $50 daily budget (in micros)
target_cpa_micros: 25000000, // $25 target CPA
networks: ["SEARCH", "SEARCH_PARTNERS"],
locations: ["US"], // Country codes
languages: ["en"],
start_date: "2026-04-01",
end_date: "2026-06-30"
});
// Returns: campaign resource name and IDjavascript
// Tool: create_search_campaign
// 创建新的Google搜索营销活动
const campaign = await mcp.call_tool("create_search_campaign", {
customer_id: "1234567890",
campaign_name: "Q2 2026 CRM Software Campaign",
budget_amount_micros: 50000000, // 每日预算50美元(微单位)
target_cpa_micros: 25000000, // 目标CPA为25美元
networks: ["SEARCH", "SEARCH_PARTNERS"],
locations: ["US"], // 国家代码
languages: ["en"],
start_date: "2026-04-01",
end_date: "2026-06-30"
});
// 返回:营销活动资源名称和IDAdd Keywords to Ad Group
向广告组添加关键词
javascript
// Tool: add_keywords
// Adds keywords with match types and bids
const keywords = await mcp.call_tool("add_keywords", {
customer_id: "1234567890",
ad_group_id: "987654321",
keywords: [
{
text: "best crm software",
match_type: "EXACT",
cpc_bid_micros: 5000000 // $5 max CPC
},
{
text: "crm for small business",
match_type: "PHRASE",
cpc_bid_micros: 3000000
},
{
text: "customer relationship management",
match_type: "BROAD",
cpc_bid_micros: 2000000
}
]
});javascript
// Tool: add_keywords
// 添加带匹配类型和出价的关键词
const keywords = await mcp.call_tool("add_keywords", {
customer_id: "1234567890",
ad_group_id: "987654321",
keywords: [
{
text: "best crm software",
match_type: "EXACT",
cpc_bid_micros: 5000000 // 最高CPC为5美元
},
{
text: "crm for small business",
match_type: "PHRASE",
cpc_bid_micros: 3000000
},
{
text: "customer relationship management",
match_type: "BROAD",
cpc_bid_micros: 2000000
}
]
});Keyword Research with Keyword Planner
使用关键词规划师进行关键词研究
javascript
// Tool: generate_keyword_ideas
// Gets keyword suggestions with volume and CPC data
const ideas = await mcp.call_tool("generate_keyword_ideas", {
customer_id: "1234567890",
seed_keywords: ["project management software", "task tracking tool"],
location_ids: ["2840"], // United States
language_id: "1000", // English
include_adult_keywords: false
});
// Returns: keyword text, avg monthly searches, competition, low/high CPC bidjavascript
// Tool: generate_keyword_ideas
// 获取带搜索量和CPC数据的关键词建议
const ideas = await mcp.call_tool("generate_keyword_ideas", {
customer_id: "1234567890",
seed_keywords: ["project management software", "task tracking tool"],
location_ids: ["2840"], // 美国
language_id: "1000", // 英语
include_adult_keywords: false
});
// 返回:关键词文本、平均月搜索量、竞争程度、最低/最高CPC出价Create Responsive Search Ad
创建响应式搜索广告
javascript
// Tool: create_responsive_search_ad
// Creates an RSA with multiple headlines and descriptions
const ad = await mcp.call_tool("create_responsive_search_ad", {
customer_id: "1234567890",
ad_group_id: "987654321",
headlines: [
"Best CRM Software 2026",
"Try Our CRM Free Today",
"Top-Rated CRM Platform",
"Manage Customers Easily",
"CRM Built for Growth"
],
descriptions: [
"Free 14-day trial. No credit card required. Get started in minutes.",
"Loved by 10,000+ businesses. Intuitive interface, powerful features."
],
final_urls: ["https://example.com/crm"],
path1: "crm",
path2: "free-trial"
});javascript
// Tool: create_responsive_search_ad
// 创建带有多个标题和描述的RSA
const ad = await mcp.call_tool("create_responsive_search_ad", {
customer_id: "1234567890",
ad_group_id: "987654321",
headlines: [
"Best CRM Software 2026",
"Try Our CRM Free Today",
"Top-Rated CRM Platform",
"Manage Customers Easily",
"CRM Built for Growth"
],
descriptions: [
"Free 14-day trial. No credit card required. Get started in minutes.",
"Loved by 10,000+ businesses. Intuitive interface, powerful features."
],
final_urls: ["https://example.com/crm"],
path1: "crm",
path2: "free-trial"
});Get Campaign Performance Report
获取营销活动绩效报告
javascript
// Tool: get_campaign_performance
// Retrieves detailed campaign metrics
const performance = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
campaign_id: "111222333",
date_range: "LAST_7_DAYS",
metrics: [
"impressions",
"clicks",
"ctr",
"cost_micros",
"conversions",
"conversion_value",
"cost_per_conversion",
"roas"
],
segment_by: "date" // Daily breakdown
});javascript
// Tool: get_campaign_performance
// 获取详细的营销活动指标
const performance = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
campaign_id: "111222333",
date_range: "LAST_7_DAYS",
metrics: [
"impressions",
"clicks",
"ctr",
"cost_micros",
"conversions",
"conversion_value",
"cost_per_conversion",
"roas"
],
segment_by: "date" // 按日细分
});Manage Negative Keywords
管理否定关键词
javascript
// Tool: add_negative_keywords
// Adds negative keywords to prevent unwanted clicks
const negatives = await mcp.call_tool("add_negative_keywords", {
customer_id: "1234567890",
campaign_id: "111222333",
keywords: [
{ text: "free", match_type: "BROAD" },
{ text: "cheap", match_type: "BROAD" },
{ text: "download", match_type: "PHRASE" }
]
});javascript
// Tool: add_negative_keywords
// 添加否定关键词以避免不必要的点击
const negatives = await mcp.call_tool("add_negative_keywords", {
customer_id: "1234567890",
campaign_id: "111222333",
keywords: [
{ text: "free", match_type: "BROAD" },
{ text: "cheap", match_type: "BROAD" },
{ text: "download", match_type: "PHRASE" }
]
});Create Ad Extensions
创建广告附加信息
javascript
// Tool: create_sitelinks
// Adds sitelink extensions to campaigns
const sitelinks = await mcp.call_tool("create_sitelinks", {
customer_id: "1234567890",
campaign_id: "111222333",
sitelinks: [
{
link_text: "Pricing",
final_urls: ["https://example.com/pricing"],
description1: "Flexible plans",
description2: "Start from $29/mo"
},
{
link_text: "Features",
final_urls: ["https://example.com/features"],
description1: "All-in-one CRM",
description2: "Sales, marketing, support"
}
]
});javascript
// Tool: create_sitelinks
// 向营销活动添加站点链接附加信息
const sitelinks = await mcp.call_tool("create_sitelinks", {
customer_id: "1234567890",
campaign_id: "111222333",
sitelinks: [
{
link_text: "Pricing",
final_urls: ["https://example.com/pricing"],
description1: "Flexible plans",
description2: "Start from $29/mo"
},
{
link_text: "Features",
final_urls: ["https://example.com/features"],
description1: "All-in-one CRM",
description2: "Sales, marketing, support"
}
]
});Meta Ads Tools
Meta Ads工具
List All Campaigns
列出所有营销活动
javascript
// Tool: meta_list_campaigns
// Lists all Meta ad campaigns
const campaigns = await mcp.call_tool("meta_list_campaigns", {
account_id: "act_1234567890",
fields: ["name", "status", "objective", "daily_budget", "lifetime_budget"],
include_insights: true,
date_preset: "last_30d"
});javascript
// Tool: meta_list_campaigns
// 列出所有Meta广告营销活动
const campaigns = await mcp.call_tool("meta_list_campaigns", {
account_id: "act_1234567890",
fields: ["name", "status", "objective", "daily_budget", "lifetime_budget"],
include_insights: true,
date_preset: "last_30d"
});Create a Campaign
创建营销活动
javascript
// Tool: meta_create_campaign
// Creates a new Meta Ads campaign
const campaign = await mcp.call_tool("meta_create_campaign", {
account_id: "act_1234567890",
name: "Q2 Lead Generation Campaign",
objective: "OUTCOME_LEADS", // OUTCOME_AWARENESS, OUTCOME_ENGAGEMENT, OUTCOME_TRAFFIC, OUTCOME_SALES
status: "PAUSED", // Create paused, enable later
special_ad_categories: [] // Or ["CREDIT", "EMPLOYMENT", "HOUSING"]
});javascript
// Tool: meta_create_campaign
// 创建新的Meta Ads营销活动
const campaign = await mcp.call_tool("meta_create_campaign", {
account_id: "act_1234567890",
name: "Q2 Lead Generation Campaign",
objective: "OUTCOME_LEADS", // OUTCOME_AWARENESS、OUTCOME_ENGAGEMENT、OUTCOME_TRAFFIC、OUTCOME_SALES
status: "PAUSED", // 创建时暂停,之后启用
special_ad_categories: [] // 或["CREDIT", "EMPLOYMENT", "HOUSING"]
});Create Ad Set with Targeting
创建带定向的广告组
javascript
// Tool: meta_create_ad_set
// Creates an ad set with budget, schedule, and targeting
const adSet = await mcp.call_tool("meta_create_ad_set", {
account_id: "act_1234567890",
campaign_id: "23850000000000000",
name: "US Adults 25-45 Desktop",
optimization_goal: "LEAD_GENERATION",
billing_event: "IMPRESSIONS",
bid_amount: 500, // $5.00 in cents
daily_budget: 5000, // $50.00
start_time: "2026-04-01T00:00:00+0000",
end_time: "2026-06-30T23:59:59+0000",
targeting: {
geo_locations: {
countries: ["US"]
},
age_min: 25,
age_max: 45,
genders: [0], // 0 = all, 1 = male, 2 = female
publisher_platforms: ["facebook", "instagram"],
facebook_positions: ["feed", "right_hand_column"],
device_platforms: ["desktop"]
}
});javascript
// Tool: meta_create_ad_set
// 创建带预算、日程和定向的广告组
const adSet = await mcp.call_tool("meta_create_ad_set", {
account_id: "act_1234567890",
campaign_id: "23850000000000000",
name: "US Adults 25-45 Desktop",
optimization_goal: "LEAD_GENERATION",
billing_event: "IMPRESSIONS",
bid_amount: 500, // 5.00美元(美分单位)
daily_budget: 5000, // 50.00美元
start_time: "2026-04-01T00:00:00+0000",
end_time: "2026-06-30T23:59:59+0000",
targeting: {
geo_locations: {
countries: ["US"]
},
age_min: 25,
age_max: 45,
genders: [0], // 0=全部,1=男性,2=女性
publisher_platforms: ["facebook", "instagram"],
facebook_positions: ["feed", "right_hand_column"],
device_platforms: ["desktop"]
}
});Create Lead Form
创建线索表单
javascript
// Tool: meta_create_lead_form
// Creates a native lead generation form
const leadForm = await mcp.call_tool("meta_create_lead_form", {
page_id: "1234567890",
name: "CRM Demo Request Form",
follow_up_action_url: "https://example.com/thank-you",
privacy_policy_url: "https://example.com/privacy",
questions: [
{ type: "FULL_NAME" },
{ type: "EMAIL" },
{ type: "PHONE_NUMBER" },
{
type: "CUSTOM",
key: "company_size",
label: "Company Size",
type: "MULTIPLE_CHOICE",
options: ["1-10", "11-50", "51-200", "200+"]
}
],
context_card: {
title: "Get a Free Demo",
content: "See how our CRM can help your business grow.",
button_text: "Get Started"
}
});javascript
// Tool: meta_create_lead_form
// 创建原生线索生成表单
const leadForm = await mcp.call_tool("meta_create_lead_form", {
page_id: "1234567890",
name: "CRM Demo Request Form",
follow_up_action_url: "https://example.com/thank-you",
privacy_policy_url: "https://example.com/privacy",
questions: [
{ type: "FULL_NAME" },
{ type: "EMAIL" },
{ type: "PHONE_NUMBER" },
{
type: "CUSTOM",
key: "company_size",
label: "Company Size",
type: "MULTIPLE_CHOICE",
options: ["1-10", "11-50", "51-200", "200+"]
}
],
context_card: {
title: "Get a Free Demo",
content: "See how our CRM can help your business grow.",
button_text: "Get Started"
}
});Upload Image Creative
上传图片创意
javascript
// Tool: meta_upload_image
// Uploads an image for use in ads
const image = await mcp.call_tool("meta_upload_image", {
account_id: "act_1234567890",
file_url: "https://example.com/ad-image.jpg",
// OR
// file_path: "/path/to/local/image.jpg"
});
// Returns: image hash to use in ad creativesjavascript
// Tool: meta_upload_image
// 上传用于广告的图片
const image = await mcp.call_tool("meta_upload_image", {
account_id: "act_1234567890",
file_url: "https://example.com/ad-image.jpg",
// 或
// file_path: "/path/to/local/image.jpg"
});
// 返回:用于广告创意的图片哈希值Create Ad Creative
创建广告创意
javascript
// Tool: meta_create_ad_creative
// Creates an ad creative with image/video
const creative = await mcp.call_tool("meta_create_ad_creative", {
account_id: "act_1234567890",
name: "CRM Demo Ad Creative",
object_story_spec: {
page_id: "1234567890",
link_data: {
image_hash: "a1b2c3d4e5f6", // From meta_upload_image
link: "https://example.com/demo",
message: "Manage your customers better with our all-in-one CRM. Start your free trial today!",
name: "Try Our CRM Free",
description: "No credit card required. Get started in minutes.",
call_to_action: {
type: "SIGN_UP",
value: {
link: "https://example.com/signup"
}
}
}
}
});javascript
// Tool: meta_create_ad_creative
// 创建带图片/视频的广告创意
const creative = await mcp.call_tool("meta_create_ad_creative", {
account_id: "act_1234567890",
name: "CRM Demo Ad Creative",
object_story_spec: {
page_id: "1234567890",
link_data: {
image_hash: "a1b2c3d4e5f6", // 来自meta_upload_image
link: "https://example.com/demo",
message: "Manage your customers better with our all-in-one CRM. Start your free trial today!",
name: "Try Our CRM Free",
description: "No credit card required. Get started in minutes.",
call_to_action: {
type: "SIGN_UP",
value: {
link: "https://example.com/signup"
}
}
}
}
});Create Custom Audience
创建自定义受众
javascript
// Tool: meta_create_custom_audience
// Creates a custom audience for targeting
const audience = await mcp.call_tool("meta_create_custom_audience", {
account_id: "act_1234567890",
name: "Website Visitors - Last 30 Days",
subtype: "WEBSITE", // WEBSITE, CUSTOMER_LIST, APP_USERS, ENGAGEMENT
retention_days: 30,
pixel_id: "1234567890123456",
rule: {
inclusions: {
operator: "or",
rules: [
{
event_sources: [{
type: "pixel",
id: "1234567890123456"
}],
retention_seconds: 2592000, // 30 days
filter: {
operator: "and",
filters: [
{
field: "url",
operator: "i_contains",
value: "/product"
}
]
}
}
]
}
}
});javascript
// Tool: meta_create_custom_audience
// 创建用于定向的自定义受众
const audience = await mcp.call_tool("meta_create_custom_audience", {
account_id: "act_1234567890",
name: "Website Visitors - Last 30 Days",
subtype: "WEBSITE", // WEBSITE、CUSTOMER_LIST、APP_USERS、ENGAGEMENT
retention_days: 30,
pixel_id: "1234567890123456",
rule: {
inclusions: {
operator: "or",
rules: [
{
event_sources: [{
type: "pixel",
id: "1234567890123456"
}],
retention_seconds: 2592000, // 30天
filter: {
operator: "and",
filters: [
{
field: "url",
operator: "i_contains",
value: "/product"
}
]
}
}
]
}
}
});Create Lookalike Audience
创建相似受众
javascript
// Tool: meta_create_lookalike_audience
// Creates a lookalike audience from a seed audience
const lookalike = await mcp.call_tool("meta_create_lookalike_audience", {
account_id: "act_1234567890",
name: "Lookalike - Top Customers",
origin_audience_id: "23850000000000000", // Seed custom audience
lookalike_spec: {
type: "similarity",
ratio: 0.01, // Top 1% similarity
country: "US"
}
});javascript
// Tool: meta_create_lookalike_audience
// 从种子受众创建相似受众
const lookalike = await mcp.call_tool("meta_create_lookalike_audience", {
account_id: "act_1234567890",
name: "Lookalike - Top Customers",
origin_audience_id: "23850000000000000", // 种子自定义受众
lookalike_spec: {
type: "similarity",
ratio: 0.01, // 相似度前1%
country: "US"
}
});Get Ad Performance Insights
获取广告绩效洞察
javascript
// Tool: meta_get_insights
// Retrieves performance metrics with breakdowns
const insights = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890", // Account, campaign, ad set, or ad ID
level: "ad", // account, campaign, adset, or ad
date_preset: "last_30d",
fields: [
"impressions",
"clicks",
"ctr",
"spend",
"cpc",
"cpm",
"reach",
"frequency",
"conversions",
"cost_per_conversion",
"roas"
],
breakdowns: ["age", "gender"] // Segment data by demographics
});javascript
// Tool: meta_get_insights
// 获取带细分维度的绩效指标
const insights = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890", // 账户、营销活动、广告组或广告ID
level: "ad", // account、campaign、adset或ad
date_preset: "last_30d",
fields: [
"impressions",
"clicks",
"ctr",
"spend",
"cpc",
"cpm",
"reach",
"frequency",
"conversions",
"cost_per_conversion",
"roas"
],
breakdowns: ["age", "gender"] // 按人口统计数据细分
});Google Analytics 4 Tools
Google Analytics 4工具
Run Standard Report
运行标准报告
javascript
// Tool: ga4_run_report
// Runs a standard GA4 report
const report = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [
{
start_date: "30daysAgo",
end_date: "today"
}
],
dimensions: [
{ name: "sessionSource" },
{ name: "sessionMedium" },
{ name: "sessionCampaignName" }
],
metrics: [
{ name: "sessions" },
{ name: "totalUsers" },
{ name: "conversions" },
{ name: "totalRevenue" }
],
order_bys: [
{
metric: { metric_name: "sessions" },
desc: true
}
],
limit: 10
});javascript
// Tool: ga4_run_report
// 运行标准GA4报告
const report = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [
{
start_date: "30daysAgo",
end_date: "today"
}
],
dimensions: [
{ name: "sessionSource" },
{ name: "sessionMedium" },
{ name: "sessionCampaignName" }
],
metrics: [
{ name: "sessions" },
{ name: "totalUsers" },
{ name: "conversions" },
{ name: "totalRevenue" }
],
order_bys: [
{
metric: { metric_name: "sessions" },
desc: true
}
],
limit: 10
});Get Realtime Data
获取实时数据
javascript
// Tool: ga4_run_realtime_report
// Gets current active users and events
const realtime = await mcp.call_tool("ga4_run_realtime_report", {
property_id: "properties/123456789",
dimensions: [
{ name: "country" },
{ name: "deviceCategory" }
],
metrics: [
{ name: "activeUsers" },
{ name: "screenPageViews" }
],
minute_ranges: [
{ start_minutes_ago: 5, end_minutes_ago: 0 }
]
});javascript
// Tool: ga4_run_realtime_report
// 获取当前活跃用户和事件数据
const realtime = await mcp.call_tool("ga4_run_realtime_report", {
property_id: "properties/123456789",
dimensions: [
{ name: "country" },
{ name: "deviceCategory" }
],
metrics: [
{ name: "activeUsers" },
{ name: "screenPageViews" }
],
minute_ranges: [
{ start_minutes_ago: 5, end_minutes_ago: 0 }
]
});List Key Events (Conversions)
列出关键事件(转化)
javascript
// Tool: ga4_list_key_events
// Lists all conversion events
const keyEvents = await mcp.call_tool("ga4_list_key_events", {
property_id: "properties/123456789"
});
// Returns: event name, counting_method, custom/defaultjavascript
// Tool: ga4_list_key_events
// 列出所有转化事件
const keyEvents = await mcp.call_tool("ga4_list_key_events", {
property_id: "properties/123456789"
});
// 返回:事件名称、统计方式、自定义/默认Get Available Dimensions and Metrics
获取可用维度和指标
javascript
// Tool: ga4_get_metadata
// Lists all available dimensions and metrics
const metadata = await mcp.call_tool("ga4_get_metadata", {
property_id: "properties/123456789"
});
// Returns: dimension/metric API names, UI names, descriptions, data typesjavascript
// Tool: ga4_get_metadata
// 列出所有可用维度和指标
const metadata = await mcp.call_tool("ga4_get_metadata", {
property_id: "properties/123456789"
});
// 返回:维度/指标API名称、UI名称、描述、数据类型Run Pivot Report
运行透视报告
javascript
// Tool: ga4_run_pivot_report
// Creates a pivot table style report
const pivotReport = await mcp.call_tool("ga4_run_pivot_report", {
property_id: "properties/123456789",
date_ranges: [
{ start_date: "2026-01-01", end_date: "2026-03-31" }
],
dimensions: [
{ name: "sessionSource" },
{ name: "deviceCategory" }
],
metrics: [
{ name: "sessions" },
{ name: "conversions" }
],
pivots: [
{
field_names: ["deviceCategory"],
limit: 5,
order_bys: [
{
metric: { metric_name: "sessions" },
desc: true
}
]
}
]
});javascript
// Tool: ga4_run_pivot_report
// 创建数据透视表样式的报告
const pivotReport = await mcp.call_tool("ga4_run_pivot_report", {
property_id: "properties/123456789",
date_ranges: [
{ start_date: "2026-01-01", end_date: "2026-03-31" }
],
dimensions: [
{ name: "sessionSource" },
{ name: "deviceCategory" }
],
metrics: [
{ name: "sessions" },
{ name: "conversions" }
],
pivots: [
{
field_names: ["deviceCategory"],
limit: 5,
order_bys: [
{
metric: { metric_name: "sessions" },
desc: true
}
]
}
]
});Cross-Platform Patterns
跨平台模式
Compare Google Ads vs Meta Ads Performance
对比Google Ads与Meta Ads绩效
javascript
// Get Google Ads performance
const googleAds = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS",
metrics: ["cost_micros", "conversions", "conversion_value"]
});
// Get Meta Ads performance
const metaAds = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890",
level: "account",
date_preset: "last_30d",
fields: ["spend", "conversions", "conversion_values"]
});
// Calculate ROAS for each
const googleROAS = googleAds.conversion_value / (googleAds.cost_micros / 1000000);
const metaROAS = metaAds.conversion_values / metaAds.spend;
// Compare and allocate budgetjavascript
// 获取Google Ads绩效
const googleAds = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS",
metrics: ["cost_micros", "conversions", "conversion_value"]
});
// 获取Meta Ads绩效
const metaAds = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890",
level: "account",
date_preset: "last_30d",
fields: ["spend", "conversions", "conversion_values"]
});
// 计算各自的ROAS
const googleROAS = googleAds.conversion_value / (googleAds.cost_micros / 1000000);
const metaROAS = metaAds.conversion_values / metaAds.spend;
// 对比并分配预算Correlate Ad Spend with GA4 Conversions
将广告支出与GA4转化关联
javascript
// Get ad spend from both platforms
const googleSpend = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS",
metrics: ["cost_micros"]
});
const metaSpend = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890",
date_preset: "last_30d",
fields: ["spend"]
});
// Get GA4 conversion data by source
const ga4Conversions = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
dimensions: [{ name: "sessionSource" }],
metrics: [{ name: "conversions" }, { name: "totalRevenue" }],
dimension_filter: {
filter: {
field_name: "sessionSource",
in_list_filter: {
values: ["google", "facebook", "instagram"]
}
}
}
});
// Analyze attribution discrepanciesjavascript
// 获取两个平台的广告支出
const googleSpend = await mcp.call_tool("get_campaign_performance", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS",
metrics: ["cost_micros"]
});
const metaSpend = await mcp.call_tool("meta_get_insights", {
object_id: "act_1234567890",
date_preset: "last_30d",
fields: ["spend"]
});
// 获取按来源划分的GA4转化数据
const ga4Conversions = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
dimensions: [{ name: "sessionSource" }],
metrics: [{ name: "conversions" }, { name: "totalRevenue" }],
dimension_filter: {
filter: {
field_name: "sessionSource",
in_list_filter: {
values: ["google", "facebook", "instagram"]
}
}
}
});
// 分析归因差异Unified Campaign Health Dashboard
统一营销活动健康仪表盘
javascript
// Function to check all campaigns across platforms
async function getCampaignHealth() {
const googleCampaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_7_DAYS"
});
const metaCampaigns = await mcp.call_tool("meta_list_campaigns", {
account_id: "act_1234567890",
include_insights: true,
date_preset: "last_7d"
});
const ga4Traffic = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
dimensions: [{ name: "sessionSource" }],
metrics: [{ name: "sessions" }, { name: "bounceRate" }, { name: "conversions" }]
});
// Flag campaigns with ROAS < 2.0, high bounce rate, or declining performance
const alerts = [];
googleCampaigns.forEach(campaign => {
if (campaign.roas < 2.0) {
alerts.push({
platform: "Google Ads",
campaign: campaign.name,
issue: "Low ROAS",
value: campaign.roas
});
}
});
return { googleCampaigns, metaCampaigns, ga4Traffic, alerts };
}javascript
// 检查全平台所有营销活动的函数
async function getCampaignHealth() {
const googleCampaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_7_DAYS"
});
const metaCampaigns = await mcp.call_tool("meta_list_campaigns", {
account_id: "act_1234567890",
include_insights: true,
date_preset: "last_7d"
});
const ga4Traffic = await mcp.call_tool("ga4_run_report", {
property_id: "properties/123456789",
date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
dimensions: [{ name: "sessionSource" }],
metrics: [{ name: "sessions" }, { name: "bounceRate" }, { name: "conversions" }]
});
// 标记ROAS < 2.0、高跳出率或绩效下滑的营销活动
const alerts = [];
googleCampaigns.forEach(campaign => {
if (campaign.roas < 2.0) {
alerts.push({
platform: "Google Ads",
campaign: campaign.name,
issue: "Low ROAS",
value: campaign.roas
});
}
});
return { googleCampaigns, metaCampaigns, ga4Traffic, alerts };
}Common Workflows
常见工作流
Complete Campaign Launch (Google Ads)
完整营销活动上线(Google Ads)
- Create campaign with
create_search_campaign - Create ad groups with
create_ad_group - Add keywords with
add_keywords - Create ads with
create_responsive_search_ad - Add extensions with ,
create_sitelinkscreate_callouts - Set up negative keywords with
add_negative_keywords - Enable campaign with
resume_campaign
- 使用创建营销活动
create_search_campaign - 使用创建广告组
create_ad_group - 使用添加关键词
add_keywords - 使用创建广告
create_responsive_search_ad - 使用、
create_sitelinks添加附加信息create_callouts - 使用设置否定关键词
add_negative_keywords - 使用启用营销活动
resume_campaign
A/B Test Setup (Meta Ads)
A/B测试设置(Meta Ads)
- Create campaign with
meta_create_campaign - Create two ad sets with different targeting using
meta_create_ad_set - Upload images with
meta_upload_image - Create creatives with (different copy/images)
meta_create_ad_creative - Create ads linking creatives to ad sets
- Monitor performance with and breakdown by ad set
meta_get_insights
- 使用创建营销活动
meta_create_campaign - 使用创建两个带不同定向的广告组
meta_create_ad_set - 使用上传图片
meta_upload_image - 使用创建创意(不同文案/图片)
meta_create_ad_creative - 创建广告将创意与广告组关联
- 使用监控绩效并按广告组细分
meta_get_insights
Audience Retargeting Flow
受众再营销流程
Google Ads:
- Create remarketing list with
create_remarketing_list - Add website visitors based on URL rules
- Apply to campaign with
update_campaign_targeting
Meta Ads:
- Create custom audience with (website visitors)
meta_create_custom_audience - Create lookalike with
meta_create_lookalike_audience - Use in ad set targeting
Google Ads:
- 使用创建再营销列表
create_remarketing_list - 根据URL规则添加网站访客
- 使用应用到营销活动
update_campaign_targeting
Meta Ads:
- 使用创建自定义受众(网站访客)
meta_create_custom_audience - 使用创建相似受众
meta_create_lookalike_audience - 在广告组定向中使用
Performance Optimization Routine
绩效优化流程
javascript
// Weekly optimization script
async function optimizeWeeklyCampaigns() {
// 1. Identify underperforming keywords
const keywords = await mcp.call_tool("list_keywords", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_7_DAYS"
});
const lowQualityKeywords = keywords.filter(kw =>
kw.quality_score < 5 || kw.ctr < 0.02
);
// 2. Pause low performers
for (const kw of lowQualityKeywords) {
await mcp.call_tool("pause_keyword", {
customer_id: "1234567890",
keyword_id: kw.id
});
}
// 3. Find high-converting search terms
const searchTerms = await mcp.call_tool("get_search_terms", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS"
});
const winningTerms = searchTerms.filter(st =>
st.conversions > 5 && st.conversion_rate > 0.05
);
// 4. Add as exact match keywords
for (const term of winningTerms) {
await mcp.call_tool("add_keywords", {
customer_id: "1234567890",
ad_group_id: term.ad_group_id,
keywords: [
{ text: term.text, match_type: "EXACT", cpc_bid_micros: term.avg_cpc * 1.2 }
]
});
}
// 5. Check budget pacing
const campaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true
});
for (const campaign of campaigns) {
const pacingRatio = campaign.spend_last_7d / (campaign.daily_budget * 7);
if (pacingRatio > 0.9 && campaign.roas > 3.0) {
// Increase budget for high performers
await mcp.call_tool("update_campaign", {
customer_id: "1234567890",
campaign_id: campaign.id,
daily_budget_micros: campaign.daily_budget * 1.2 * 1000000
});
}
}
}javascript
// 每周优化脚本
async function optimizeWeeklyCampaigns() {
// 1. 识别表现不佳的关键词
const keywords = await mcp.call_tool("list_keywords", {
customer_id: "1234567890",
include_metrics: true,
date_range: "LAST_7_DAYS"
});
const lowQualityKeywords = keywords.filter(kw =>
kw.quality_score < 5 || kw.ctr < 0.02
);
// 2. 暂停表现差的关键词
for (const kw of lowQualityKeywords) {
await mcp.call_tool("pause_keyword", {
customer_id: "1234567890",
keyword_id: kw.id
});
}
// 3. 找到高转化搜索词
const searchTerms = await mcp.call_tool("get_search_terms", {
customer_id: "1234567890",
date_range: "LAST_30_DAYS"
});
const winningTerms = searchTerms.filter(st =>
st.conversions > 5 && st.conversion_rate > 0.05
);
// 4. 添加为精确匹配关键词
for (const term of winningTerms) {
await mcp.call_tool("add_keywords", {
customer_id: "1234567890",
ad_group_id: term.ad_group_id,
keywords: [
{ text: term.text, match_type: "EXACT", cpc_bid_micros: term.avg_cpc * 1.2 }
]
});
}
// 5. 检查预算节奏
const campaigns = await mcp.call_tool("list_campaigns", {
customer_id: "1234567890",
include_metrics: true
});
for (const campaign of campaigns) {
const pacingRatio = campaign.spend_last_7d / (campaign.daily_budget * 7);
if (pacingRatio > 0.9 && campaign.roas > 3.0) {
// 为高绩效营销活动增加预算
await mcp.call_tool("update_campaign", {
customer_id: "1234567890",
campaign_id: campaign.id,
daily_budget_micros: campaign.daily_budget * 1.2 * 1000000
});
}
}
}Troubleshooting
故障排除
Connection Issues
连接问题
Symptom: MCP server not appearing in Claude/ChatGPT
Solutions:
- Verify the URL is correct in your config file
- Restart the AI assistant completely (quit and relaunch)
- Check for JSON syntax errors in config (use a JSON validator)
- Ensure you have network connectivity to the MCP endpoint
症状:MCP服务器未在Claude/ChatGPT中显示
解决方案:
- 验证配置文件中的URL是否正确
- 完全重启AI助手(退出后重新启动)
- 检查配置中的JSON语法错误(使用JSON验证工具)
- 确保您的网络可以连接到MCP端点
Authentication Failures
认证失败
Symptom: "Authentication required" or "Invalid token" errors
Solutions:
- Re-run the OAuth flow by using any tool that requires authentication
- Check that you've granted all required permissions during OAuth
- Verify your account has appropriate access (MCC structure for Google Ads)
- For Google Ads: ensure your developer token is approved (not in test mode)
- For Meta Ads: check that your app has the required permissions (ads_management, ads_read)
症状:“需要认证”或“无效令牌”错误
解决方案:
- 使用任何需要认证的工具重新运行OAuth流程
- 检查您在OAuth过程中是否授予了所有必要权限
- 验证您的账户具有适当的访问权限(Google Ads的MCC结构)
- 对于Google Ads:确保您的开发者令牌已获批(非测试模式)
- 对于Meta Ads:检查您的应用是否具有所需权限(ads_management、ads_read)
API Errors
API错误
Symptom: "RESOURCE_EXHAUSTED" or rate limit errors
Solutions:
- Google Ads has per-developer and per-account rate limits
- Meta Ads has per-app rate limits
- Implement exponential backoff in automation scripts
- Batch operations when possible (e.g., add multiple keywords at once)
Symptom: "PERMISSION_DENIED" errors
Solutions:
- Google Ads: Verify you have the correct customer ID (10 digits, no dashes)
- Meta Ads: Ensure the ad account ID includes "act_" prefix
- GA4: Use the full property ID format "properties/123456789"
- Check account access levels (standard vs. admin)
症状:“RESOURCE_EXHAUSTED”或速率限制错误
解决方案:
- Google Ads有针对开发者和账户的速率限制
- Meta Ads有针对应用的速率限制
- 在自动化脚本中实现指数退避机制
- 尽可能批量操作(例如,一次性添加多个关键词)
症状:“PERMISSION_DENIED”错误
解决方案:
- Google Ads:验证您使用的客户ID是否正确(10位数字,无连字符)
- Meta Ads:确保广告账户ID包含“act_”前缀
- GA4:使用完整的属性ID格式“properties/123456789”
- 检查账户访问级别(标准 vs 管理员)
Data Discrepancies
数据差异
Symptom: GA4 conversions don't match Google Ads conversions
Solutions:
- Check attribution window settings (GA4 vs. Google Ads may differ)
- Verify conversion import settings if using GA4 goals in Google Ads
- Compare date ranges (GA4 uses property timezone, Google Ads uses account timezone)
- Check for conversion tag implementation issues
症状:GA4转化数据与Google Ads转化数据不匹配
解决方案:
- 检查归因窗口设置(GA4与Google Ads可能不同)
- 如果在Google Ads中使用GA4目标,验证转化导入设置
- 对比日期范围(GA4使用属性时区,Google Ads使用账户时区)
- 检查转化标签实施问题
Tool Not Found
工具未找到
Symptom: AI assistant says it can't find a specific tool
Solutions:
- Use to see all available tools
list_tools() - Check the exact tool name (case-sensitive, underscores not hyphens)
- Verify your MCP server version supports that tool
- Some tools require platform-specific authentication first
症状:AI助手表示无法找到特定工具
解决方案:
- 使用查看所有可用工具
list_tools() - 检查工具的准确名称(区分大小写,使用下划线而非连字符)
- 验证您的MCP服务器版本支持该工具
- 部分工具需要先完成平台特定的认证
Best Practices
最佳实践
Security
安全
- Never hardcode credentials in scripts — always use environment variables
- Use the OAuth flow provided by the MCP server, don't try to manage tokens manually
- For production automation, implement proper error handling and logging
- Rotate access tokens regularly if self-hosting
- 永远不要在脚本中硬编码凭据——始终使用环境变量
- 使用MCP服务器提供的OAuth流程,不要尝试手动管理令牌
- 对于生产自动化,实施适当的错误处理和日志记录
- 若自行托管,定期轮换访问令牌
Performance
性能
- Batch API calls when possible (add multiple keywords, create multiple ads)
- Use date range filters to reduce data transfer
- Cache frequently accessed data (account hierarchies, metadata)
- Implement rate limiting in automation scripts
- 尽可能批量调用API(添加多个关键词、创建多个广告)
- 使用日期范围过滤器减少数据传输
- 缓存频繁访问的数据(账户层级、元数据)
- 在自动化脚本中实施速率限制
Campaign Management
营销活动管理
- Always create campaigns in status, review before enabling
PAUSED - Use labels extensively for organization and bulk operations
- Set up conversion tracking before launching campaigns
- Use experiments for A/B testing instead of manual splits
- 始终以状态创建营销活动,审核后再启用
PAUSED - 广泛使用标签进行组织和批量操作
- 在启动营销活动前设置转化追踪
- 使用实验进行A/B测试,而非手动拆分
Data Analysis
数据分析
- Segment data by time period to identify trends
- Use GA4 as source of truth for cross-platform attribution
- Compare platform-reported conversions with GA4 for discrepancies
- Export large datasets to BigQuery for advanced analysis
- 按时间段细分数据以识别趋势
- 使用GA4作为跨平台归因的数据源
- 对比平台报告的转化数据与GA4数据,查找差异
- 将大型数据集导出到BigQuery进行高级分析
Additional Resources
额外资源
- Official Documentation: Model Context Protocol Spec
- Project Repository: [github.com/irinabuht12-oss
- 官方文档:Model Context Protocol Spec
- 项目仓库:[github.com/irinabuht12-oss