Ads Structure Analysis
Scope: This Is an Orchestration Skill, Not a New MCP Tool
This skill does not map to a single MCP tool of its own — it orchestrates two existing read tools, each already covered by its own skill:
get_ads_perf→ sparkx-query-ads-performanceget_entity_metadata→ sparkx-query-entity-metadata
Dependency — install these two base skills alongside this one:
sparkx-query-ads-performance,sparkx-query-entity-metadata. Skills install as sibling directories under your current agent's skills root (.claude/skills/<name>/for Claude Code; the equivalent root for other agents — see the supported-agents table), which is exactly what the../query-.../…links above (and elsewhere in this doc) resolve against — if a base skill isn't installed there, those links won't resolve and this skill can't run. Install both first.
Read those two SKILL.md files first (parameter formats, field-naming rules, the Ratio Metric Display Rule) plus references/platform-notes.md (auth flow, error handling, pagination, date-range limits, currency rules). This document only covers logic specific to structural analysis; it doesn't repeat what the base skills already document.
Rewritten against the new tool's conventions from the start — carries forward the same discipline established across sparkx-weekly-ads-report/sparkx-monthly-ads-report: full profileIds resolution rules, currency-aware thresholds, output-language adaptivity, disclosed sampling fallback, and zero-denominator handling.
Output Language: Always Match the User, Never Hard-Code Chinese or English
The worked examples and output templates below are written in Chinese (matching this product's primary customer base), but they are structural illustrations, not literal text to copy verbatim. Generate the actual report in whatever language the user asked in. When calling get_ads_perf, also set the language parameter (zh/en/ja) to match the customer's language. get_entity_metadata has no language parameter — it's not in that tool's documented parameter list. Localize its enum values using the returned {field}Text companion fields, or sparkx-query-entity-metadata's own enum-i18n.md if a given enum has no Text companion — don't pass language to get_entity_metadata expecting it to have the same effect as on get_ads_perf.
When to Use
Trigger phrases: 结构分析, 结构合理吗, 类型对比, 站点对比, SP/SB/SD 结构, SB 新客, 工作日 周末, structure analysis, campaign type breakdown
User roles: ads managers, account managers, ads ops doing a deep-dive (not a periodic report)
Core question: how is spend distributed across this dimension, is that distribution matched by efficiency, and where's the structural imbalance
Not for:
- Periodic recaps (WoW/MoM cadence) →
sparkx-weekly-ads-report/sparkx-monthly-ads-report - Single-campaign root-cause investigation → ACOS root-cause investigation example
- Product-level diagnosis →
sparkx-product-diagnosis; keyword-level diagnosis → a dedicated skill (not yet built)
Input Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
profileIds |
array[long] | No | — | See "Resolving profileIds" below |
breakdownBy |
enum | No | campaignType |
campaignType | marketplace | portfolio | dayOfWeek | hourOfDay. See "Breakdown Dimensions" for how each is actually queried — some require client-side derivation, not a native groupBy |
dateStart / dateEnd |
string (YYYY-MM-DD) |
No | Trailing 30 days ending yesterday | The analysis window. Must satisfy get_ads_perf's 90-day span / 15-month lookback caps like any other call |
focusMetrics |
array[string] | No | ["Spend", "Sales", "ACOS", "ROAS", "CPA"] |
Which metrics drive the share/efficiency comparison. CPA is included by default alongside ACOS — the product's own canonical "Campaign Type Analysis" board treats them as equally core, not ACOS alone. Must be valid for the entities involved — check sparkx-query-ads-performance's Metrics × Entity Support Matrix |
includeTrend |
bool | No | true |
Whether to include a per-segment trend view (Step 3) alongside the single-period snapshot — on by default, matching how the product's own dashboards present this analysis (trend lines, not just a static table). Set false for a lighter, snapshot-only response |
subScenario |
enum | No | — | spDeepDive | sbNtb | weekdayWeekend. See "Sub-Scenarios" below. sbvCreative (creative-type breakdown) is not offered — see Data Boundaries for why |
Resolving profileIds
Always call get_user_authorized_context first to get the authorized profiles list, then apply exactly one of these cases:
- The user named specific store(s) → resolve the name(s) against the authorized list and query only the matching profile(s).
- The user explicitly said "all stores" / "全账号" / equivalent → query all authorized
profileIds. - The user didn't name a store, and there's only one authorized profile → use it directly — there's nothing to ask.
- The user didn't name a store, and there are multiple authorized profiles:
- 5 or fewer → you may default to using all of them.
- More than 5 → do not silently roll everyone up. Hand the user the
profileslist and ask them to pick one, several, or explicitly confirm "all stores" first.
Case 4's threshold exists because a silent multi-store aggregate can hide a single store's structural pattern behind a blended number, and forces an unannounced USD conversion (see "Multi-Store and Currency" below).
Breakdown Dimensions
campaignType (default) — campaign.campaignType_ (sponsoredProducts/sponsoredBrands/sponsoredDisplay). A native dimension field; group directly via select.
marketplace — profile.countryCode_. Only meaningful when profileIds spans multiple countries; if it's a single-country selection, say so and suggest campaignType or portfolio instead of producing a one-row "breakdown."
portfolio — portfolio.portfolioId_, displayed via portfolio.portfolioName_. Rows with no portfolio must be grouped as an explicit "no portfolio" bucket, not silently dropped from the total.
dayOfWeek — not a native groupBy expression. get_ads_perf's time-aggregation options are calendar day/week/month/quarter/year (see sparkx-query-ads-performance's Time Aggregation table) — there is no "bucket every Monday together regardless of week" expression. To do this breakdown: pull daily-granularity data (select: ["date"], one row per day across the window), then client-side map each row's date to a weekday name and aggregate the 4-5 occurrences of each weekday within the window yourself. Don't attempt to express this as a single server-side groupBy.
hourOfDay — available via hourly (AMS) data, with tighter limits than every other breakdown here. Query factEntity: "campaign" with timeGranularity: "hourly" and explicitly include both date and hour in select; hourly mode changes the source table but does not inject hour into the selected grouping. Aggregate the returned rows by hour client-side (same shape as dayOfWeek).
Constraints you must respect and disclose:
- Campaign level only. There is no hourly adGroup / target / placement / ASIN data —
timeGranularity: hourlyon any other entity is a hard error. So an hourly breakdown cannot be crossed withportfolioormarketplacebeyond what campaign-levelselectfields give you. - 7-day window per call, not 30 or 90. This breaks the skill's default trailing-30-day window: either narrow to ≤7 days, or split the requested window into contiguous ≤7-day calls and aggregate hour-of-day across all chunks. Call it a sample only when you deliberately cover a subset (for example, the latest 14 of 30 days), and disclose that subset. If every day is covered by non-overlapping chunks, describe it as a split full-window query, not sampling.
- Averaging: divide each hour's totals by the number of days covered, not the number of rows.
- T+2 delay hits hardest here: the most recent hours are incomplete, so drop or label the trailing partial day rather than reporting a fake evening collapse.
- Timezone is not stated for hourly buckets, so avoid strong claims like "spend peaks at 8pm local"; describe the shape ("a clear evening peak") and note the hour labels' zone is unconfirmed.
A keyword × placement structural view is also possible (factEntity: "keywordPlacement", SP only, hourly, ≤7 days) — see sparkx-query-ads-performance's hourly/AMS example. Note its AI metrics are placeholders (AISpend/AISales = 0, AIACOS/AIROAS = null), so don't put AI columns in that table.
Sub-Scenarios
spDeepDive: narrow to campaign.campaignType_ = sponsoredProducts, then further break down by campaign.targetingType_ (manual/auto) — compare manual vs auto targeting's spend share and efficiency within SP specifically. Don't confuse this with target.targetingType_, a different field with different values (keyword/target/auto/audience — categorizing the target's own type, not the campaign's manual/auto setting).
sbNtb: narrow to campaign.campaignType_ = sponsoredBrands, and add the NTB metrics (NTBOrders, NTBSales, NTBUnits, NTBOrdersRate, NTBUnitsRate, NTBSalesRate) to the metrics pulled — these are confirmed available for campaign/adGroup/target/searchTerm/productAd (not placement/asin), so request them at whichever entity level the rest of the breakdown is using. Report NTB share alongside the regular spend/efficiency breakdown, since "is SB driving new customers" is specifically what NTB answers.
weekdayWeekend: use the dayOfWeek breakdown above, then bucket further into two groups (Mon-Fri vs Sat-Sun) rather than 7 separate days, if that's what the user actually asked ("workday vs weekend" is coarser than "which specific day of the week").
Companion breakdowns customers often ask for alongside campaignType: the product's own "Campaign Type Analysis" dashboard template pairs the campaign-type view with a targeting-type breakdown (manual vs auto — covered here via spDeepDive) and a search-term match-type breakdown (broad/phrase/exact, etc.). The second one is not covered by this skill — it belongs to a future search-term-analysis skill (not yet built). If a customer's ask naturally extends into match-type territory (e.g. "结构分析完了,再看看搜索词匹配类型"), say plainly that this skill's scope stops at campaign/targeting-type structure and point them to that future capability instead of trying to fold match-type analysis into this skill's output.
Workflow
Step 1 · Define the Analysis Window
Default: trailing 30 days ending yesterday (T+2 delay — see below). If the user gives an explicit range, use it, but confirm it satisfies get_ads_perf's 90-day max span and 15-month lookback before issuing the call — if it doesn't, split into multiple ≤90-day calls per the standard procedure (see sparkx-query-ads-performance's aggregation-over-time example) rather than sending an oversized request.
T+2 data-delay check: if the window's end date is within 2 days of today, note that the most recent day(s) may not have finished processing yet.
Step 2 · Pull Data
a. Breakdown-level performance
{
"profileIds": [4404871489220462],
"factEntity": "campaign",
"dateStart": "{window start}",
"dateEnd": "{window end}",
"select": ["campaign.campaignType_"],
"metrics": ["Impressions", "Clicks", "Spend", "Sales", "Conversions"],
"pageSize": 500,
"userContext": "Structure analysis - breakdown by campaign type"
}
select changes per breakdownBy: ["campaign.campaignType_"] for campaignType, ["profile.countryCode_"] for marketplace, ["portfolio.portfolioId_", "portfolio.portfolioName_"] for portfolio, ["date"] for dayOfWeek (aggregate to weekday buckets client-side per "Breakdown Dimensions" above), and ["date", "hour"] plus timeGranularity: "hourly" for hourOfDay (aggregate the same hour across dates client-side). Recompute ACOS/ROAS/CTR/CVR from the summed base metrics per segment rather than requesting them directly alongside a select that spans the whole window in one row per segment — request the base metrics (Impressions/Clicks/Spend/Sales/Conversions) and derive the ratios, so there's no ambiguity about which period/grouping a pre-computed ratio belongs to.
If subScenario is set, this call changes further — don't run the plain breakdown call above and expect Step 5 to somehow retrofit it:
spDeepDive: add{"campaign.campaignType_": "sponsoredProducts"}tofilters, and addcampaign.targetingType_toselectalongside (or instead of, if not also doing the basecampaignTypebreakdown) thebreakdownBydimension.sbNtb: add{"campaign.campaignType_": "sponsoredBrands"}tofilters, and addNTBOrders/NTBSales/NTBUnits/NTBOrdersRate/NTBUnitsRate/NTBSalesRatetometrics.weekdayWeekend: same as thedayOfWeekbreakdown's call shape (select: ["date"]) — the Mon-Fri/Sat-Sun bucketing happens client-side afterward, no additional field needed here.
b. Segment-level entity config (only if the diagnosis needs config context, e.g. explaining why a segment underperforms): get_entity_metadata for the relevant entity (campaign, portfolio, etc.) to pull status/settings for the segments identified as imbalanced in Step 4.
c. Segment-level weekly trend (only when includeTrend=true, the default): same shape as (a), but select adds a weekly time-aggregation expression alongside the breakdown dimension — e.g. ["campaign.campaignType_", "toMonday(parseDateTime32BestEffort(date)) as week"] — so each segment gets one row per week across the window instead of one row for the whole period. Use weekly, not daily, granularity for the trend view: a 30-day default window is ~4-5 weekly points per segment, which reads cleanly in a text report; daily granularity (30 points × N segments) is what the product's own web dashboard can render as a line chart but is too dense for a markdown table. Recompute ACOS/CPA per segment per week from that week's own summed base metrics — never average pre-computed weekly ratios across weeks, and never derive a week's ratio from another week's base metrics.
Exception for breakdownBy=hourOfDay: do not issue this separate weekly-trend call. The 24-point intraday curve derived from Step 2a's date + hour rows is already this mode's trend output, and its ≤7-day source window does not produce a meaningful 4-5-point weekly series. Treat includeTrend as satisfied by the intraday curve; only add a day-by-day comparison when the user explicitly asks, using the same rows client-side rather than a weekly aggregation expression.
⚠️ breakdownBy=dayOfWeek or subScenario=weekdayWeekend need a different shape here — the breakdown "dimension" isn't a native field to add alongside week the way campaign.campaignType_/profile.countryCode_/portfolio.portfolioId_ are. There's no server-side field for "which weekday" to combine with a week aggregation. Instead: select: ["date"] only (same as the base breakdown call), pull daily rows across the whole window, then client-side derive two labels per row — the weekday/weekend segment (per "Breakdown Dimensions" above) and the week bucket it falls in — and organize the trend as segment × week from those two derived labels together. Don't expect the server to return a "Monday" or "weekday" row directly at any granularity.
Fully paginate before analyzing — loop page while hasNextPage is true. If full pagination would be impractical at scale (e.g. very many portfolios or campaigns), you may fall back to a spend-ranked sample instead of the full population — this fallback must be disclosed explicitly, stating what was actually covered, and a degraded section must not fail the whole analysis — produce whatever's complete and mark only the affected part as partial.
Step 3 · Compute Share and Efficiency Per Segment
For each segment in the breakdown: share of total (segment Spend / account total Spend, and separately segment Sales / account total Sales — report both, they can diverge) plus the segment's own ACOS/ROAS/CTR/CVR/CPA recomputed from its summed base metrics (CPA = Spend/Conversions).
Zero-denominator handling: a segment with Sales = 0 has undefined ACOS — don't compute it, don't treat it as infinite; report the segment's Spend and note "no sales this period" instead of a fabricated ratio. Likewise, a segment with Conversions = 0 has undefined CPA.
Trend view (when includeTrend=true): using Step 2c's weekly-grouped data, show each segment's ACOS/CPA across the weeks in the window — the product's own canonical dashboard treats this trend, not just the period snapshot, as the primary way to read structural efficiency. Call out any segment whose trend moved meaningfully within the window (e.g. "SB's ACOS was stable at ~24% for three weeks, then jumped to 31% in the last week") — a snapshot alone would average that shift away and miss it.
Ratio-metric display rule: the confirmed percentage metrics used here — ACOS, CTR, CVR, TACOS, and the listed NTB *Rate metrics — are already pre-scaled ×100. Append %, never re-scale. Do not apply this rule to an unlisted ratio-shaped field solely from its name. ROAS/CPA are plain ratios/unit-costs, not percentages — no %. See the base skill's Ratio Metric Display Rule.
Step 4 · Diagnose Structural Imbalance
Compare each segment's spend share against its efficiency (ACOS/ROAS) and sales share relative to the account average:
- Over-invested, underperforming: spend share meaningfully higher than sales share, and/or ACOS meaningfully worse than the account average — flag as a candidate for reallocating budget away from.
- Under-invested, strong performer: spend share meaningfully lower than sales share, and/or ACOS meaningfully better than the account average — flag as a candidate for scaling up.
- Currency-aware thresholds: define "meaningfully" using percentage-point gaps (share) and relative ACOS deviation (e.g. ">20% worse than account average"), not a hardcoded absolute dollar gap — a fixed dollar threshold breaks for non-USD single-store analyses the same way it would in the weekly/monthly report skills.
- Don't diagnose a segment with negligible spend share (e.g. <2% of total) as a meaningful imbalance either way — flag it as "too small to be structurally significant" instead, to avoid noise from long-tail segments.
Step 5 · Sub-Scenario Section (if subScenario was requested)
Add the relevant specialized section per "Sub-Scenarios" above — this supplements, not replaces, the base breakdown from Steps 3-4.
Step 6 · Structural Recommendations
Derive 3-5 recommendations from Step 4's findings, each with: action + target segment + evidence (share %, efficiency numbers). Same discipline as the report skills — correlation, not causation: a structural finding ("SD share grew while overall ACOS worsened") is not proof SD caused the ACOS change unless you've actually isolated SD's own ACOS as the driver; say what the data shows, not more.
Multi-Store and Currency
When profileIds spans multiple stores:
- All monetary metrics from
get_ads_perfauto-aggregate to USD — label dollar amounts "(USD)" explicitly. - Add
profile.profileId_/profile.profileName_to Step 2a'sselectif you need to know which store each row belongs to (e.g. combiningmarketplacebreakdown with multi-store detail) — but don't add it when the point is one blended breakdown across all selected stores, since that would fragment each segment's row by store instead of aggregating it.
Output Format
Naming entities in this report
Nobody reading this report knows an internal id, and the ids get_ads_perf returns are
Amazon's anyway. So:
- Every entity column and every sentence uses the name —
campaignName,adGroupName,asinTitle. ACampaigncolumn holds a campaign name, never a number. - Keep ids in your working data regardless. Period-over-period joins must be by id, because names get duplicated and renamed — that requirement does not change. What changes is only what reaches the page.
- An export gets both. If the user asked for CSV / Excel / "something I can reconcile",
add an id column next to the name. The id to publish is the Amazon one, which is what
get_ads_perfalready gives you. - In
structured_reportmode the entity/target fields carry the name; when ids were asked for, add a separate key for the Amazon id rather than gluing both into one string.
Full convention, including the managed-group and product-ad exceptions:
references/platform-notes.md -> "Naming things in your
answer".
markdown mode
# 广告结构分析 · {profile_name}
**维度**:{campaignType / marketplace / portfolio / dayOfWeek}
**周期**:{dateStart} ~ {dateEnd}
{If data may be incomplete due to T+2 delay, or a section is based on a partial sample, note it here}
## 一、结构占比
| 分段 | 花费占比 | 销售额占比 | ACOS | ROAS | CPA |
|---|---|---|---|---|---|
| SP | {pct} | {pct} | {acos}% | {roas} | {cpa} |
| SB | ... | ... | ... | ... | ... |
| SD | ... | ... | ... | ... | ... |
{仅当 includeTrend=true 时展示——按周展示每个分段的 ACOS/CPA 走势,不只是期末快照}
### 分段周度趋势(ACOS / CPA)
| 分段 | 第1周 | 第2周 | 第3周 | 第4周 | ... |
|---|---|---|---|---|---|
| SP · ACOS | {pct}% | ... | ... | ... | ... |
| SP · CPA | {value} | ... | ... | ... | ... |
| SB · ACOS | ... | ... | ... | ... | ... |
| SB · CPA | ... | ... | ... | ... | ... |
{如果某个分段的趋势中途有明显变化,单独点出来,不要让期末快照把这个变化平均掉}
## 二、结构失衡诊断
- **过度投入/表现不佳**:{segment} — 花费占比 {pct},销售额占比仅 {pct},ACOS 比账户均值差 {pct}
- **投入不足/表现优秀**:{segment} — ...
{Segments below the 2% spend-share floor: mention briefly as "too small to be structurally significant," don't over-analyze}
## 三、{子场景标题,若有 subScenario}
{spDeepDive: manual vs auto targeting 对比表;sbNtb: NTB 指标专区;weekdayWeekend: 工作日 vs 周末对比表}
## 四、结构调整建议
1. **{action}** {target}
- 依据:{data}
2. ...
---
_生成时间:{timestamp} · 数据源:SparkX AI MCP · Skill: sparkx-ads-structure-analysis v{version}_
structured_report mode
{
"dimension": "campaignType",
"period": {"start": "...", "end": "..."},
"dataFreshnessWarning": null,
"segments": [{"segment": "...", "spendShare": ..., "salesShare": ..., "acos": ..., "roas": ..., "cpa": ..., "tooSmallToAnalyze": false}],
"trend": null,
"imbalances": [{"segment": "...", "type": "overinvested|underinvested", "evidence": "..."}],
"subScenario": null,
"recommendations": [{"priority": 1, "action": "...", "target": "...", "evidence": "..."}]
}
"trend" is null when includeTrend=false; otherwise it's [{"segment": "...", "weekly": [{"weekStart": "...", "acos": ..., "cpa": ...}]}] — one entry per segment, each with its own array of weekly points.
Data Boundaries
sbvCreative(creative-type breakdown) is not offered by this skill.get_ads_perf/get_entity_metadata's documented fields don't include a "creative type" dimension anywhere in the campaign/adGroup/target/productAd entity tables — this isn't a documented capability of either tool. Don't invent a field name for it; if a customer asks for creative-level SBV analysis, say plainly this data isn't currently queryable via these tools rather than guessing at an undocumented field.dayOfWeekis a client-side derivation, not a server aggregation — see "Breakdown Dimensions." Accuracy depends on correctly mapping eachdateto a weekday; don't get this wrong for reports spanning a daylight-saving or year boundary (unlikely at a 30-day default window, but worth checking for longer custom windows).- No historical structural snapshot —
get_entity_metadatahas no point-in-time capability, so "how has the structure changed since 6 months ago" can only be approximated by re-running this analysis over a past window withget_ads_perf, not by queryingget_entity_metadatafor a past config state. - Structural findings are correlational, not causal — see Step 6.
Example Call
User input:
看下 Demo US 最近 30 天 SP/SB/SD 结构合不合理
Skill flow:
- Resolve the profile:
get_user_authorized_context→ find Demo US'sprofileId breakdownBy = campaignType, window = trailing 30 days ending yesterday- Run Steps 2-6
- Output the markdown report — in Chinese, since the user asked in Chinese
Error Handling
Follows the shared error envelope used by both underlying tools (isError/errorType, see references/platform-notes.md).
| Situation | Handling |
|---|---|
profileIds is empty |
Follow "Resolving profileIds" above — ask only when those rules require it |
Any call returns isError: true |
Handle per errorType — invalid_params usually means a construction bug in this skill's own call; rate_limited → wait retryAfterSeconds |
effectiveProfileIds doesn't match requested profileIds |
Explain the scope mismatch before concluding "no data" |
A segment has Sales = 0 |
Report Spend and "no sales," don't compute ACOS against a zero denominator |
| A degraded/sampled section | Disclose what was covered; don't fail the whole analysis over one segment's pagination trouble |
Not Covered by This Skill
- Periodic WoW/MoM cadence recaps →
sparkx-weekly-ads-report/sparkx-monthly-ads-report - Creative-type (SBV) breakdown → not currently a queryable capability, see Data Boundaries
- Product-level diagnosis →
sparkx-product-diagnosis - Keyword/search-term-level diagnosis → a dedicated skill (not yet built)
- Single-campaign root-cause investigation → ACOS root-cause investigation example