/workmagic-skills:attribution-data-queryfrom workmagic-skills
Translates explicit data requests into Cube.dev SQL queries and returns results. Handles metrics, dimensions, time ranges, and filters for the Attribution domain.
Ships in workmagic-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Translate the user's explicit data request into a precise Cube.dev SQL query and return results. No estimation, no fabrication, no proactive dashboard creation. This is the default skill for all query-type requests in the Attribution domain.
Trigger condition: the user's request explicitly states (or strongly implies) most of:
Examples that should NOT trigger — route to another skill instead:
| Input pattern | Route to |
|---|---|
| Ambiguous request ("Show me my numbers" / "How is Meta doing") | attribution-intent-clarification |
| "Why" question ("Why did sales drop?") | attribution-anomaly-diagnosis |
| Comparing 2+ attribution models ("Compare iDDA vs last_click") | attribution-model-comparison |
| Business-label dimension ("by region" / "by audience" / "by brand") | attribution-custom-dimension |
| "Create / build a dashboard" | build a live-data dashboard artifact — the dashboard skill (an html/react live view), not a native platform dashboard. If the ask is a recurring business review ("weekly overview", "monthly review"), route to attribution-weekly-report — it owns the board spec for each cadence |
| "Send me a weekly/daily report" | attribution-weekly-report |
Fields to parse from user input:
| Field | Required? | Description / default |
|---|---|---|
| dataset | Required | One of: channel_attribution (by channel) / ads_attribution (by campaign/ad) / creative_attribution (by creative) / order_sales (raw orders, no attribution split). Infer from user phrasing; never ask user to pick a DataSet name. |
| metric | Required | Extract from user input. Always call dashboard-metrics-list to validate the field name before using it. Never guess. |
| dimension | Required | Validate against dashboard-metrics-list. For ads_attribution / creative_attribution with NC dimensions (Product Group, Asset Type, Creator name, etc.), pass tenantId to fan out tenant-specific propertyNames. |
| time_range | Has default | Default: past 7 days. When user doesn't specify, use the default and inform them in one sentence ("Defaulting to the past 7 days — let me know if you want a different window"). Do not ask back. |
| attribution_model | Has default | Resolved per §3.2. Filter via WHERE attr_model_name = ''. |
| sales_platform_scope | Has default | Default: all sales platforms — use attr_all_sales / attr_all_orders, NOT Shopify-only. Use attr_shopify_sales only when the user explicitly asks for Shopify / DTC alone. Per-platform breakdown via the dedicated measures → references/sales-platform-scope.md. |
| filters | Optional | Extract from input ("only Meta", "ROAS > 2", "exclude test"). |
| order_by / limit | Optional | "top 10" / "most" implies sorting — order descending by the implied key. |
Default resolution rules (see references for details):
references/time-range-resolution.mdreferences/granularity-default.mdStep 1: Parse the request
Map natural language into the input fields. Resolve silently: today's date (re-fetch — never hard-code) → time window → attribution model → sales-platform scope (default all platforms, attr_all_*) → DataSet → dimensions → metrics.
Step 2: Pick the DataSet (by dimension)
channel_attributionads_attributioncreative_attributionorder_salesads_attributionlift_test_result exists but belongs to lift-test domain — route there if user asks about lift test resultsStep 3: database-query-ask first (MANDATORY)
Ask database-query-ask about the warehouse's Cube.dev schema patterns. database-query-run requires the ctx timestamp it produces. Skipping fails execution.
Step 4: Validate fields via dashboard-metrics-list
ads_attribution / creative_attribution: pass tenantId to fan out tenant-specific propertyNames (e.g., Product Group, Asset Type). Use propertyName exactly as returned (case-sensitive).database-query-ask answer. If the question needs a field that isn't there (common asks: ad / ad set delivery status, ad account name), don't try a guessed column such as ad_status or account_name — tell the user that field isn't available in the attribution data and answer with the fields that are.Step 5: Construct & execute SQL via database-query-run
🛑 HARD RULE — copy a template first, then fill placeholders
BEFORE writing any SQL, you MUST match the user's query pattern to one of the 6 templates in
templates/:
templates/01-channel-roas.sql— single-platform channel-level ROAStemplates/02-top-n-campaigns.sql— Top-N campaigns by metrictemplates/03-period-over-period.sql— WoW / MoM comparison (2 separate queries)templates/04-creative-headlines.sql— creative-level (JSON-array headlines)templates/05-actual-store-sales.sql— actual store sales (NOT attribution)templates/06-spend-by-platform.sql— total ad spend across all platforms, by platformCopy the template, then fill placeholders (
<tenant_id>/<attr_model>/<platform>/<start_date>/<end_date>). Do NOT write SQL from scratch — past agents have produced wrong queries (case-sensitive platform names, missingHAVING SUM(ad_spend) > 0, average-of-ratios ROAS, window functions Cube rejects).If none of the 6 templates fit — pause and tell the user what's requested is outside the verified set, ask CSM, do NOT improvise. Pitfalls + when-to-use guidance for each template →
references/sql-examples.md. Full worked walkthrough →examples/example-A-meta-roas-last-week.md.
🛑 Spend totals come from the channel-level table only. Any platform-level or all-platform spend figure (totals, "spend by platform", the spend half of a ROAS) uses
dws_view_copilot_attr_channel_level_daily_latest. The ad-level table loads the most recent day later, so the same window sums lower there (observed: one day short by ~$2.2K across Meta / OpenAI). Use ad-level only when the user asked for a campaign / ad set / ad breakdown, and do not present its sum as the platform total.
💡 Don't take the bait — never average ROAS across rows
Tempting design: when comparing campaigns / days, compute ROAS per row first, then average. Don't. That's "average of ratios" and is mathematically wrong — a $64-spend campaign with one lucky order produces 122.76x ROAS that buries real top performers (vs the correct ratio-of-sums 3.44x).
Always
SUM(sales) / NULLIF(SUM(spend), 0)at the final aggregation level. Same applies to CAC, ROAS, conversion rate — any ratio metric.
ctx timestamp from Step 3 (ISO 8601)NOT LIKE / NOT IN)attr_model_name dimension — required on the channel / ad / creative attribution tables; database-query-run rejects a query on them without itevent_date >= '2026-04-01'). No MySQL date functions (DATE_FORMAT, DATE_SUB, CURDATE, INTERVAL); for weekly / monthly figures group by event_date and roll up client-sidereferences/sql-examples.md. Required reading before writing SQL.Step 6: Return results
| Tool | Required? | Purpose |
|---|---|---|
| database-query-ask | Required (first) | Consult Cube.dev schema patterns before SQL. |
| dashboard-metrics-list | Required | Validate metric / dimension field names exist on the chosen DataSet. |
| database-query-run | Required | Execute the Cube.dev SQL query. |
| tenant-list | Optional | Look up tenantId when needed to fan out NC dimensions on dashboard-metrics-list. |
dashboard skill: an html/react view wired to the data), not a wall
of table dumped in chat. Carry the same measurement identity (sales-platform scope +
model) onto the artifact. When in doubt between the two, a clean chat table is fine —
don't force an artifact for a genuinely simple ask.references/sales-platform-scope.md. Never print the raw DataSet technical name (channel_attribution / ads_attribution / creative_attribution / order_sales) — see rule 8 below; those are internal identifiers, not customer-facing labelsattribution-anomaly-diagnosisreferences/sql-examples.md BEFORE writing SQL — do not write SQL from scratch. The 6 templates cover channel ROAS / Top-N campaigns / WoW comparison / creative headlines / actual store sales / spend by platform. If none fit, pause and ask CSM; do not improvise.database-query-ask before SQL — database-query-run requires the ctx it produces; will fail at executiondashboard-metrics-list — guessing field names causes SQL errors / wrong datachannel_attribution / ads_attribution etc.) to userFull edge case & routing catalog → references/edge-cases.md
| Skill | Relationship |
|---|---|
| attribution-intent-clarification | Upstream: handles ambiguous requests, then routes back to data-query once clarified |
| attribution-anomaly-diagnosis | Downstream: handles "why" questions |
| attribution-model-comparison | Downstream: handles multi-model comparisons |
| attribution-custom-dimension | Downstream: handles business-label dimensions that require Naming Convention config |
| attribution-edge-routing | Downstream: handles requests outside the Attribution domain's capability |
examples/example-A-meta-roas-last-week.md (opens in a new tab)references/attribution-model.md (opens in a new tab)references/edge-cases.md (opens in a new tab)references/failure-modes.md (opens in a new tab)references/granularity-default.md (opens in a new tab)references/sales-platform-scope.md (opens in a new tab)references/sql-examples.md (opens in a new tab)references/time-range-resolution.md (opens in a new tab)templates/01-channel-roas.sql (opens in a new tab)templates/02-top-n-campaigns.sql (opens in a new tab)templates/03-period-over-period.sql (opens in a new tab)templates/04-creative-headlines.sql (opens in a new tab)templates/05-actual-store-sales.sql (opens in a new tab)templates/06-spend-by-platform.sql (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
16 skills in this plugin
/attribution-anomaly-diagnosisDiagnose "why" questions about attribution anomalies — attribution=0 (no attributed orders), and sudden drops, spikes or retroactive changes in attributed numbers. Do NOT use for "show me numbers" — that's attribution-data-query./attribution-custom-dimensionHandle attribution queries sliced by a business label ("by audience" / "by region" / "by brand") that is not a native field — it lives in campaign names and only becomes queryable once a Naming Convention (NC) rule is configured./attribution-edge-routingRecognize when a user request falls outside attribution's capability boundary and route it gracefully — to another WM product (MBO / Lift Test / Creative Magic / Ads Magic / Audience Magic), to a human (CSM / DS / Eng), or to a clean decline that bridges back to what attribution can answer.Other plugins' skills for the same job
npx claudepluginhub workmagicio/skills --plugin workmagic-skills