Marketing Dashboard Builder
A dashboard that fills itself from live data instead of from exports. The skill agrees what the dashboard is for, pulls the numbers, reads the destination before touching it, and shows every write it plans to make. Nothing is written until the user says yes to the exact payloads.
Two more modes sit on the same pull: a Looker Studio dashboard (or a review of one you already have) and a month close for finance (budget vs actual on every line, accruals, a re-forecast and a reconciliation of platform spend against invoices). Each has its own section after Step 7.
Before you start
With the InsightfulPipe MCP connected (at least one data source and one destination: Google Sheets, Notion, Slack or Airtable), the skill pulls the numbers and writes them itself. With no connection, every mode still runs on what the user pastes or uploads: platform exports or CSVs, a budget plan, invoices, or a screenshot or field list of a Looker Studio dashboard. It then drafts the same spec, tables and payloads from those figures, says on each line that they came from the paste, and skips the calls below.
- Call
query_contextswithrequest="accounts"and no platform to see every connected source. Then call it again with each platform you will read or write, and noteworkspace_id,brand_idand each id:account_id,ad_account_id,property_id,site_url,spreadsheet_id, the Notion workspace, the Slackteam_id. If this call already returnsrate_limit_exceeded, nothing can be read yet: say when the limit clears (Step 3, "When a call fails") and stop. - Pick one business. A brand can hold several businesses (an agency's clients, test accounts). Group the sources by account name and ask which business the dashboard is for. Never put two businesses in one dashboard. If an account's owner is unclear, ask before using it.
- Call
query_contextswithrequest="actions_details"for every action this skill uses on each platform, and follow the body shapes it returns. - Ask four things, and use the defaults if the user doesn't say:
- The job. A full dashboard, a weekly KPI snapshot, a daily spend log, budget vs actual, a campaign plan check, a weekly report, a Looker Studio dashboard or a review of one ("Mode: Looker Studio dashboard"), or a month close ("Mode: month close"). Default: the full dashboard, which includes the first six.
- The destination. Google Sheets, Looker Studio (through a staged Sheets tab), Notion, Slack or Airtable. Default: Google Sheets, with the weekly report also drafted for Notion and Slack when they are connected.
- The result that matters (leads, sign-ups, purchases, revenue) and a target cost per result. Default: the conversions each ad platform counts, and no target.
- Budgets. A budget tab in the sheet, numbers in chat, or none. Default: each Google Ads campaign's own daily budget.
Step 1: write the dashboard spec
Before pulling anything, write a short spec and ask the user to approve it. A dashboard nobody designed ends up as a wall of numbers.
| Part | What to write |
|---|---|
| Reader and decision | Who opens it and what they decide with it (for example "the owner, Monday: move budget between campaigns or not") |
| Questions | 3 to 5 questions it must answer, in the reader's words |
| KPIs | Up to 8 for the top of the dashboard. For each: name, formula, source, grain and target if one exists |
| Layout | The tabs or sections and what each holds (Step 4 gives the default) |
| Refresh | How often it is updated and by whom. This skill writes when asked; it does not schedule itself |
| Not included | Sources that aren't connected for this business, and metrics the reader asked for that no source holds |
Use these definitions unless the user gives their own, and keep the same definition in every tab:
| KPI | Formula | Source |
|---|---|---|
| Spend | sum of cost | each ad platform |
| CTR | clicks ÷ impressions | ad platforms |
| Conversions | the platform's own count, per platform | ad platforms |
| Cost per result | spend ÷ conversions | ad platforms |
| ROAS | conversion value ÷ spend | ad platforms, only when values are set |
| Sessions, key events | GA4 totals | GA4 |
| Cost per key event | spend ÷ GA4 key events | ad platforms and GA4: the one cost per result across platforms when two or more ad platforms run |
| Organic clicks | Search Console clicks + Bing clicks | Search Console, Bing |
Only list a KPI whose source is connected for this business. Platform conversions overlap, so never add them across platforms into one total. Show them side by side.
Step 2: check the destination
Read the destination before drafting a single write. The writes in Step 6 depend on what is already there.
Google Sheets. List the tabs, then look at each tab you plan to write to:
{"platform": "google-sheets", "action": "list_sheets", "spreadsheet_id": "<SPREADSHEET_ID>", "include_grid_properties": true}
{"platform": "google-sheets", "action": "get_sheet_peak", "spreadsheet_id": "<SPREADSHEET_ID>", "sheet_id": "<SHEET_ID>"}
get_sheet_peak returns the header row and only 2 data rows; on an empty tab available_columns comes back empty. To find the last filled row and the dates already logged, read the key column of the tab (Date for Daily, Week start for Weekly) once its headers are confirmed. A column that doesn't exist comes back as an empty list, not an error, so an empty answer only means "no rows" after get_sheet_peak showed the column:
{"platform": "google-sheets", "action": "query_sheet_data", "spreadsheet_id": "<SPREADSHEET_ID>", "sheet_id": "<SHEET_ID>", "select": "Date", "limit": 20000}
The next empty row is the number of rows returned + 2 (row 1 holds the headers). rowCount from list_sheets is the size of the grid, not the filled rows, so never use it to find the next row.
- A tab the dashboard needs that doesn't exist gets created (
create_sheet). Its title must be unique in the spreadsheet. - A tab that exists with other headers belongs to someone else. Don't write into it; create a new tab with a different name and say so.
- A log tab (Daily, Weekly) with our headers gets new rows below its last filled row; never overwrite a filled row. The Campaigns and Budget tabs, once created by this skill, are rewritten under their header row each run.
- An empty default tab (no headers, no rows, like a new spreadsheet's
Sheet1) is left as it is; the dashboard tabs are created next to it.
Notion. Find the parent page for the report:
{"platform": "notion", "action": "search", "query": "", "filter": {"value": "page", "property": "object"}, "page_size": 10}
The report becomes a new page under the page the user picks. Run the search with an empty query to list every page the integration can see. If it returns no pages, nothing is shared with the integration yet: draft the page payload anyway, mark it blocked, and ask the user to share a parent page with the InsightfulPipe MCP's Notion integration.
Slack. Find the channel:
{"platform": "slack", "action": "list_conversations", "types": "public_channel,private_channel", "exclude_archived": true, "auto_paginate": true}
Use the channel id, not its name. Each channel in the response carries is_member; the app can post only where it is true. When it is false for the user's channel, draft the message anyway, mark it blocked, and ask the user to invite the app to that channel.
Airtable (untested until connected). No Airtable base was connected when this skill was built, so these calls follow the actions_details shapes but have not been run. Find the base (list_bases), then the table and its fields (list_tables with baseId), then the records already there:
{"platform": "airtable", "action": "list_records", "baseId": "<BASE_ID>", "tableIdOrName": "Campaigns",
"fields": ["Campaign ID", "Week start"], "pageSize": 100}
Follow offset in the response to read the next page. Field names must match the table exactly.
Step 3: pull the data
Pull daily rows for the whole window once; every tab is built from the same pull, so the numbers agree across tabs.
Windows.
- Weekly snapshot and report: the last complete Monday-to-Sunday week, against the week before.
- Daily log: from the day after the last date already in the Daily tab up to yesterday. A new log starts on the first day of the budget period.
- Budget vs actual: the current month to date when at least 7 days have passed, otherwise the last complete month.
- One pull covers all of them: from the earliest start to the latest end.
Every read goes through query_data with the platform in the body. Run each call on every account of the business on that platform. Skip a platform that isn't connected for this business and list it as not connected.
Google Ads (account currency, then daily cost by campaign, then budgets):
{"platform": "google-ads", "action": "gaql", "account_id": "<GOOGLE_ADS_ID>",
"query": "SELECT customer.descriptive_name, customer.currency_code, customer.time_zone FROM customer"}
{"platform": "google-ads", "action": "gaql", "account_id": "<GOOGLE_ADS_ID>",
"query": "SELECT segments.date, campaign.id, campaign.name, campaign.status, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.conversions, metrics.conversions_value FROM campaign WHERE segments.date BETWEEN 'START' AND 'END' AND metrics.impressions > 0"}
{"platform": "google-ads", "action": "gaql", "account_id": "<GOOGLE_ADS_ID>",
"query": "SELECT campaign.id, campaign.name, campaign.status, campaign.advertising_channel_type, campaign_budget.amount_micros, campaign_budget.period FROM campaign WHERE campaign.status != 'REMOVED'"}
Money fields end in _micros: divide by 1,000,000. Conversions can be fractional under data-driven attribution (1.3952): write them with 1 decimal. Never use a manager account; use the client accounts under it.
The budget query also returns every paused campaign the account ever had. Keep only campaigns that are enabled or spent in the budget period. When two kept campaigns share one campaign_budget resource, they get one budget row together, never the budget twice.
Meta (daily, by campaign):
{"platform": "facebook-ads", "action": "get_insights_adaccount", "ad_account_id": "<META_AD_ACCOUNT_ID>",
"level": "campaign", "time_range": {"since": "START", "until": "END"}, "time_increment": 1,
"fields": ["date_start", "campaign_id", "campaign_name", "account_currency", "spend", "impressions", "clicks", "actions", "action_values"]}
spend arrives as a string. actions is a list of {action_type, value}: count only the action types that match the result the user named (lead, complete_registration, purchase). An empty list means nothing delivered.
LinkedIn Ads (daily, account level):
{"platform": "linkedin-ads", "action": "get_account_analytics", "ad_account_id": "<LINKEDIN_AD_ACCOUNT_ID>",
"start_date": "START", "end_date": "END", "time_granularity": "DAILY",
"fields": ["dateRange", "impressions", "clicks", "costInUsd", "externalWebsiteConversions", "oneClickLeads"]}
A result is externalWebsiteConversions plus oneClickLeads. An empty list means no delivery.
Any other connected ad platform: call actions_details for its account-level stats action and add it only if the call works. TikTok, for example, is the month-close call in "Mode: month close" with dimensions ["advertiser_id", "stat_time_day"], metrics ["spend", "impressions", "clicks", "conversion"] and page_size 1000 (the default page holds only 10 rows); its daily rows go in at account level. Otherwise list it as unknown; never estimate it from another platform.
GA4 (daily):
{"platform": "google-analytics", "action": "get_report", "property_id": "<GA4_PROPERTY>",
"dimensions": ["date"], "metrics": ["sessions", "engagedSessions", "keyEvents"],
"start_date": "START", "end_date": "END"}
GA4 keeps processing for about two days. If the window ends less than two days ago, mark those days provisional.
Search Console and Bing (daily):
{"platform": "google-search-console", "action": "search_analytics", "site_url": "<GSC_SITE>",
"dimensions": ["date"], "start_date": "START", "end_date": "END", "row_limit": 500}
{"platform": "bing-webmaster", "action": "get_rank_and_traffic_stats", "site_url": "<BING_SITE>"}
Search Console lags two to three days; count the dates it returned and name its last day. Bing returns about six months of daily rows in one call with dates as /Date(<epoch ms>)/: convert them and keep the rows inside the window.
When a call fails:
rate_limit_exceeded(429). The limit covers the whole workspace on the InsightfulPipe MCP, not one platform, so every other call fails too until it clears;retry_aftercan run to hours. Ifretry_afteris 60 seconds or less, wait that long and retry once. If it is longer, stop calling: don't try the remaining sources one by one. Mark every source not yet read as unknown, "rate limited until " (now plusretry_after), show what was already pulled, and offer to pick up from there once it clears. Draft payloads from a partial pull only if the user accepts the gaps.- Reconnect or permission error: the source is broken.
- Any other failure: the source is unknown, with the reason.
- Never fill a gap with a guess or with zeros.
Run the reads one after another, never in parallel: a burst of calls is what trips the limit.
Data checks before drafting.
- Complete days. Each source returned every day of the window, or the gap is named.
- One currency. Every money source is in the same currency, or the dashboard shows each currency separately.
- Totals match. The daily rows of each source add up to what the dashboard will show for the week and the period.
Step 4: lay out the dashboard
The default Google Sheets layout has five tabs. Leave out a tab whose job the user didn't ask for, and a column whose source isn't connected.
| Tab | One row per | Columns | How it is written |
|---|---|---|---|
| Dashboard | KPI | title, date line, KPI table, last-14-days block and chart | formulas only, so it updates when rows are added |
| Daily | date x ad account | Date, Platform, Account, Spend, Impressions, Clicks, Conversions, Conversion value | appended: only dates not already in the tab |
| Weekly | Monday-to-Sunday week | Week start, Week end, Spend, Impressions, Clicks, CTR, then the result. With one ad platform: Conversions, Cost per result. With two or more: one Conversions column per platform, never a summed one. Then Sessions, Key events, Organic clicks when connected, and Cost per key event when GA4 is connected and two or more ad platforms run | appended: skipped when the week start is already there. A new tab starts with the last complete week and the week before, so the Dashboard can compare them |
| Campaigns | campaign (or account, for a platform pulled at account level) | Campaign, Platform, Status, Spend, Clicks, Conversions, Cost per result, for the last complete week. Status comes from the budget query for Google Ads; the other calls return none, so a row with spend in the week says delivering |
rewritten each run (header row kept) |
| Budget | campaign or platform | Campaign, Platform, Budget source, Period budget, Expected by today, Actual, Pace, Status | rewritten each run |
Values and formulas.
- Write raw numbers with
value_input_optionUSER_ENTEREDso Sheets treats them as numbers and dates. Write dates asYYYY-MM-DD. - Money cells get 2 decimals (
number_format0.00), on the Dashboard too (spend, cost per result, the 14-day spend column); summaries in chat round to whole units of the currency. - Derived cells are formulas, never pasted results: CTR
=IFERROR(E2/D2,""), cost per result=IFERROR(C2/G2,""). A row added later gets the same formula with its own row number. - Dashboard KPI table: "This week" reads the last row of Weekly, for example
=INDEX(Weekly!C:C,COUNTA(Weekly!A:A)), and "Last week" the row above it (COUNTA(Weekly!A:A)-1). "Change" applies the floor from Step 5:=IF(MIN(B5,C5)<100,"too small to call",B5/C5-1)(use 10 for conversions and key events). A rate row checks the floor on its count row: clicks for CTR, conversions for cost per result, key events for cost per key event. With two or more ad platforms the table shows Key events and Cost per key event instead of Conversions and Cost per result, and each platform's conversions stay in the Weekly and Campaigns tabs, side by side. - Date line: under the title, a formula that names the week the KPI table shows, for example
="Week "&TEXT(INDEX(Weekly!A:A,COUNTA(Weekly!A:A)),"yyyy-mm-dd")&" to "&TEXT(INDEX(Weekly!B:B,COUNTA(Weekly!A:A)),"yyyy-mm-dd")&", against the week before", so it moves with the KPI table. The sources and currency go on the line below it. - Last-14-days block: the first date is
=MAX(Daily!A2:A)-13and each next row adds 1; spend per date is=SUMIF(Daily!A:A,A14,Daily!D:D), and clicks the same way. Add a conversions column only when one ad platform feeds the Daily tab, because a SUMIF over several platforms adds their conversions together. A line chart on this block always shows the latest 14 days. - Freeze and bold the header row of every data tab (Daily, Weekly, Campaigns, Budget), bold the Dashboard's KPI header, show rates as percentages, and give the Pace column a colour rule (Step 5).
Notion page. Title "Weekly marketing report: to ". Blocks: a one-paragraph summary, the KPI lines (this week, last week, change), "What moved" bullets, the budget and plan findings, "Next week" bullets, and a link to the sheet. Keep under 100 blocks in one request and 2,000 characters per text block.
Slack message. At most 15 lines: the week, the KPI lines, the top two moves, one line on pacing, and the sheet link (https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit) or the Notion page link. No tables; Slack doesn't render them.
Airtable (untested until connected). A Campaigns table keyed on the platform's campaign id (one record per campaign, updated in place) and a Weekly results table (one record per week). Writes go in batches of 10 records, the most one call takes.
Step 5: the numbers the dashboard judges
What moved (weekly). Show a % change only when both weeks clear the floor: 100 for impressions, clicks or sessions, 100 in spend, 10 conversions. A rate (CTR, cost per result) uses the floor of its count (clicks, conversions) and is computed from the week's totals, never by averaging daily or campaign rates. Below the floor, show both numbers and write "too small to call". A move worth a line is a change of 20% or more in spend, impressions, clicks, conversions or sessions, above the floor, for the account or for one campaign; list the campaigns below the floor by name as too small to call. A campaign counts as below the floor only when every one of those metrics is below it; a campaign that clears the floor on any metric is judged on that metric, and if none moved 20% it gets no line. Explain it with a number from the pull (for example, a campaign's spend falling while its clicks held); if nothing in the pull explains it, write "cause not visible in this data".
Budget vs actual. Budget sources, in this order:
- A budget tab in the sheet: read its headers with
get_sheet_peak, then its rows withquery_sheet_data. - Numbers the user gives.
- Each Google Ads campaign's daily budget x the days in the period. Say that this assumes the budget didn't change during the period. Google can spend up to twice the daily budget on a single day, and holds the month to about 30.4 x the daily budget.
Then for each row:
- Expected by today = period budget x days elapsed ÷ days in the period (the whole budget for a finished period).
- Pace = actual ÷ expected.
- Status: under 0.8 is underspending, 0.8 to 1.1 is on pace, over 1.1 is overspending. With no budget, the row says "no budget" and gets no status.
- Budget changed during a finished month. When the budget comes from today's Google Ads daily budget and a whole month's pace is above 1.02, the budget must have been higher at some point in the month, because Google holds a month to about 30.4 x the daily budget. Keep the status, add a note that the expected figure is too low, and suggest checking the change history.
Add a total row only for budgets in one currency.
Campaign plan vs live. Read the plan tab the user names (get_sheet_peak, then query_sheet_data). It needs at least a campaign name; platform, budget, status and start date are used when present. Match each plan row to a live campaign by campaign id when the plan has one, else by exact name ignoring case. Report:
| Finding | When |
|---|---|
| Missing | a planned campaign has no live match |
| Not in plan | a live campaign that spent in the window has no plan row |
| Status differs | the plan says live and the campaign is paused, or the reverse |
| Budget differs | the live daily budget differs from the plan by more than 10% |
| Not started | the plan's start date has passed and the campaign had no impressions |
A platform pulled at account level (LinkedIn, TikTok) has no campaign names in the pull, so its plan rows can't be matched; say so instead of reporting them missing. If no plan tab is given, skip this check and say so. Don't build a plan from the live campaigns and then compare it with itself.
Step 6: the report and the payloads
Show the user, in this order:
- Spec from Step 1, as approved.
- Source list: each data source with one status: active, idle (the call worked and showed nothing), not connected, broken or unknown. Each destination is ready or blocked, with the reason (nothing shared in Notion, app not in the Slack channel).
- Data checks from Step 3, one line each.
- Layout preview: each tab with its header row and its first rows exactly as they will be written, including formulas.
- This week: the KPI table, what moved, budget pacing and plan findings.
- Payloads, numbered in run order, each in full and marked
not run. - After writing: the read-backs that prove it worked (Step 7).
Step 7: writes this skill can run
Only after the user says yes to the exact payloads. Each needs a Read & Write connection, and an owner, admin or operator can switch any of them off. Run them one at a time in the numbered order: create_sheet returns the sheet_id the next calls need.
| Write | Action | Notes |
|---|---|---|
| New tab | create_sheet with spreadsheet_id and a unique title |
returns sheet_id |
| Headers and rows | batch_update_cells with sheet_id and ranges (A1 range to rows), or update_cells with one range and values |
value_input_option USER_ENTERED; all ranges in one call must sit in one tab |
| Header style | format_cells with range and bold, background_color, number_format |
one call per style |
| Freeze headers | update_sheet_properties with frozen_row_count 1 |
|
| Pace colours | add_conditional_format with rule_type BOOLEAN, condition_type NUMBER_LESS or NUMBER_GREATER, condition_values, background_color |
one rule per colour |
| Chart | create_chart with chart_type LINE, data_range on the last-14-days block, title |
first column = dates |
| Notion report | create_page with parent {"page_id": ...}, a title property and children blocks |
100 blocks at most per request |
| Slack summary | post_message with a nested body: {"channel": "<id>", "text": "..."} |
|
| Airtable records | create_records with baseId, tableIdOrName and a nested body {"records": [{"fields": {...}}]}; update_records with {"records": [{"id": ..., "fields": {...}}]}, or performUpsert {"fieldsToMergeOn": ["Campaign ID"]} to update or create by campaign id |
10 records per call; untested until connected |
After writing, read back: get_sheet_peak on each tab written (headers and first rows match the preview) and query_sheet_data on the Date column (the row count grew by exactly the rows written). For Notion, the create_page result's url; for Slack, the message ts.
Never delete tabs, rows, pages or records, and never change a campaign. This skill only writes dashboards and reports.
Mode: Looker Studio dashboard
Use this mode when the reader wants the dashboard in Looker Studio, asks for a Looker Studio marketing dashboard or template, or wants an existing Looker Studio report checked.
Say this first. Looker Studio has no public API that builds pages or charts. The skill prepares everything a report needs (the spec, the data, the calculated fields, the blends) and writes the layout as numbered build steps. It can also give a Linking API URL that opens a new report already wired to the staged data, so the build starts from connected fields instead of an empty canvas.
1. Spec and source plan
Write the Step 1 spec, with pages instead of tabs. Then decide how each KPI's source reaches Looker Studio:
| Source | How it gets into the report |
|---|---|
| GA4, Search Console | Google's own connectors, added in Looker Studio by the user |
| Google Ads | Google's own connector, or the staged tab when spend from several platforms must sit in one table (the default when two or more ad platforms run) |
| Meta, LinkedIn, TikTok, Microsoft Ads, Pinterest, Snapchat, X, OpenAI Ads | the staged tab. Google builds no connector for these; the partner connectors that exist are mostly paid. This skill writes their rows into Sheets from the live pull instead |
| An existing BigQuery table of marketing data | read and mapped to the spec (below); the skill never creates or changes BigQuery tables |
| A pasted export or CSV | drafted into the staged tab's rows |
Default: every paid platform in one staged tab, LS_Daily; GA4 and Search Console on their own connectors; a blend on Date only for charts that need spend and site data together.
2. The staged tab
One long table, one row per date x platform x account x campaign. A platform pulled at account level (LinkedIn in Step 3, TikTok with its Step 3 call) gets one row per date x account with Campaign (account total).
| Column | Type in Looker Studio | Rule |
|---|---|---|
| Date | Date (YYYYMMDD) | written as YYYY-MM-DD; the platform's own day in the ad account's time zone |
| Platform, Account, Campaign | Text | the names the platform returns |
| Currency | Text | the account currency from the pull |
| Spend | Currency in the account currency | raw cost, 2 decimals |
| Impressions, Clicks | Number | |
| Conversions | Number | the platform's own count, 1 decimal |
| Conversion value | Currency | 0 when the platform has no values set |
| Spend (reporting currency) | Currency | only when accounts bill in different currencies: Spend x the rate the user gives, one named rate per month |
Keep it machine-shaped: one header row with unique names (Looker Studio needs unique headers and drops empty ones), no totals, no blank rows, no merged cells, no formulas and no ratio columns. Ratios are computed in Looker Studio (below), never stored.
Build the rows from the Step 3 pull (Google Ads by campaign and Meta by campaign, LinkedIn by account; TikTok by account with its Step 3 call; add Microsoft Ads and the others with the month-close calls below, set to daily (Microsoft Ads with aggregation Daily and a TimePeriod column, Pinterest with granularity DAY, OpenAI Ads with time_granularity daily) and with the impression, click and conversion metrics their actions_details lists), then run the Step 3 data checks. Write it with the Step 2 rules: read the tab first, append only dates not already there, and create a new tab if LS_Daily holds someone else's headers.
Refresh. A Sheets data source in Looker Studio re-reads the sheet on its data freshness setting (15 minutes by default; 1, 4 or 12 hours are the other choices), but the staged tab itself is a snapshot: it only gains days when this skill runs again and appends them. Say so in the spec's Refresh line. The skill does not schedule itself; the user can rerun the request, or put it on a schedule they run. Google's own Google Ads connector refreshes every 12 hours, which is another reason to stage Google Ads next to the others.
BigQuery instead of Sheets (read only). When the marketing data already sits in BigQuery, map that table instead of staging a Sheet:
{"platform": "bigquery", "action": "list_datasets", "max_results": 50}
{"platform": "bigquery", "action": "list_tables", "dataset_id": "<DATASET_ID>", "max_results": 100}
{"platform": "bigquery", "action": "get_table_schema", "dataset_id": "<DATASET_ID>", "table_id": "<TABLE_ID>"}
{"platform": "bigquery", "action": "run_query", "max_rows": 50,
"query": "SELECT MIN(<DATE_COL>) AS first_day, MAX(<DATE_COL>) AS last_day, COUNT(*) AS row_count, COUNT(DISTINCT <CURRENCY_COL>) AS currencies FROM `<PROJECT>.<DATASET_ID>.<TABLE_ID>`"}
run_query returns rows as rows[].f[].v, in the column order of schema.fields. Map each spec column to a table column, name what is missing, and check for duplicate keys with a GROUP BY on date, platform, account and campaign HAVING COUNT(*) > 1. Designing or loading the tables is a data-warehouse job (Go deeper).
3. Calculated fields
Create them on the data source, not on one chart, so every chart uses the same definition. Every ratio is a ratio of sums:
| Field | Formula | Type |
|---|---|---|
| CTR | SUM(Clicks) / SUM(Impressions) |
Percent |
| CPC | SUM(Spend) / SUM(Clicks) |
Currency |
| Conversion rate | SUM(Conversions) / SUM(Clicks) |
Percent |
| CPA (cost per result) | SUM(Spend) / SUM(Conversions) |
Currency |
| ROAS | SUM(Conversion value) / SUM(Spend) |
Number, 2 decimals |
| Spend share | the Spend metric with the chart's "Percent of total" comparison calculation | Percent |
Why: a stored CTR or CPA column gets SUM as its default aggregation in Looker Studio, which adds rates together, and switching it to AVG weights a 3-click day the same as a 3,000-click day. Use the reporting-currency spend field in these formulas when currencies differ, and never sum Spend across currencies.
Blended cost per lead divides all paid spend by one lead count from one source (a GA4 key event, or the CRM's count pasted in), never by the platforms' conversions added together, because each platform claims some of the same leads.
4. Blends
A blend joins up to 5 tables on equality conditions; each table is grouped by its own dimensions first, then joined. Rules for marketing data:
- Join
LS_Dailyand GA4 on Date with a full outer join, so a day with sessions and no spend (or the reverse) stays in the chart. A left or inner join silently drops those days. - Put platform and campaign charts on
LS_Dailyalone; a blend on Date has no campaign key on the GA4 side. - In the blend, compute the ratio from the blended fields (
SUM(Spend) / SUM(Key events)), never from a ratio field of either table. - A filter on Platform applies to the
LS_Dailyside only; say so in the chart's title or a note.
5. The build sheet
Hand over, in order:
- Linking API URL that creates a report with the staged tab as its data source (the user who opens it needs access to the sheet, and the new data source uses their credentials):
https://datastudio.google.com/reporting/create?ds.connector=googleSheets&ds.spreadsheetId=<SPREADSHEET_ID>&ds.worksheetId=<SHEET_ID>Addc.reportId=<TEMPLATE_REPORT_ID>to copy a report the user already likes, with the alias formds.<alias>.connectorand so on for its data source. - Data source settings: Date as Date (YYYYMMDD), money fields as Currency in the right currency, each calculated field from the table above, data freshness set.
- Pages and charts, from the spec. Default: Overview (scorecards for spend, conversions, CPA and ROAS with "previous period" comparison, spend and conversions over time, a table by platform), Campaigns (a table by campaign with CPA and conversion rate, sorted by spend), Website and search (GA4 and Search Console charts on their own connectors, plus the blended cost per lead).
- Controls: one date range control per page with a comparison period, drop-down filters for Platform and Account, and a "data through" scorecard (
MAX(Date)) so nobody reads a stale staged tab as current. - Sharing: set data source credentials to the owner's when viewers should not need access to the sheet, share the report as view only, and set scheduled email delivery if the reader wants it in the inbox.
6. Review an existing dashboard
From a screenshot, a shared link the user describes, or a list of its data sources and fields, check:
| Check | What is wrong when it fails |
|---|---|
| Rates stored as columns, aggregated with SUM or AVG | the rate is wrong for every period longer than one row |
| Platform conversions added into one total | leads counted twice or more |
| Spend summed across currencies | a meaningless total |
| A blend on Date with a left or inner join | days missing from charts and totals |
| Scorecards with no period or comparison shown | the reader can't tell what the number covers |
| Comparison periods of different length, or a partial current period against a full one | changes look bigger or smaller than they are |
| A staged source with no "data through" date | a stopped refresh looks like a quiet week |
| A filter that applies to only one side of a blend | totals that don't match the filtered table |
For each finding give what is wrong, why it misleads (with the number from the user's data when they gave one), and the fix as a formula or a setting. When a check can't be seen in what the user shared, say "not visible" instead of passing it.
7. Output and writes
Show the spec, the source plan, the staged tab's header and first rows exactly as they will be written, the data checks, the calculated fields, the blend plan, the build sheet and, for a review, the findings. The writes are Step 7's Sheets writes, numbered and marked not run: create_sheet for LS_Daily, batch_update_cells for the header and rows, then format_cells for the header. Later runs append only new dates. Nothing is written to BigQuery.
Mode: month close
Use this mode after a month ends, when finance needs marketing's actuals: planned budget against actual on every line, the reason for each gap, what to accrue, where the year will land, and whether the platforms' spend matches what was invoiced or re-billed. In-month pacing stays in Step 5's budget vs actual.
1. Inputs
- The month. Default: the last complete calendar month.
- The budget plan. One row per line per month: line, type (media or non-media), owner and amount. From a budget tab (read it with
get_sheet_peak, thenquery_sheet_data) or pasted. If the user has none, ask for it; never use the platforms' daily budgets as the plan here. - Non-media actuals: agency fees, tools, freelancers, events, content production and anything else on the plan, pasted from invoices or the books, with the period each one covers.
- Invoices and charges for media: each platform's invoice or card receipts for the month, net of tax, with any credit lines.
- Re-billing, for agencies: the client, the markup or fee rule, and the amount billed.
- Year to date: each line's actual for the earlier months of the year, and the annual budget, for the re-forecast.
2. Platform spend for the exact month
Pull each ad account's spend for the first to the last day of the month, in the account's own currency and day. Run each call on every account of the business.
- Google Ads (dates are days in
customer.time_zone):
{"platform": "google-ads", "action": "gaql", "account_id": "<GOOGLE_ADS_ID>",
"query": "SELECT segments.month, customer.currency_code, customer.time_zone, metrics.cost_micros FROM customer WHERE segments.date BETWEEN 'MONTH_START' AND 'MONTH_END'"}
- Meta and LinkedIn: the Step 3 calls with the month as the window, Meta with
levelaccountand notime_increment, LinkedIn withtime_granularityALL. - TikTok Ads (
integrated_report_basic; copy theactionvalue the helper gives).voucher_spendis the part paid with ad credits, which no invoice or card charge will show:
{"platform": "tiktok-ads", "action": "report/integrated/get/", "method": "GET",
"account_id": "<TIKTOK_ADVERTISER_ID>", "advertiser_id": "<TIKTOK_ADVERTISER_ID>",
"service_type": "AUCTION", "report_type": "BASIC", "data_level": "AUCTION_ADVERTISER",
"start_date": "MONTH_START", "end_date": "MONTH_END",
"dimensions": ["advertiser_id"], "metrics": ["spend", "cash_spend", "voucher_spend"]}
- Microsoft Ads: submit, then poll with the
ReportRequestId. SetReportTimeZoneto the account's own time zone so the month matches its invoice.
{"platform": "microsoft-ads", "action": "submit_account_performance_report", "account_id": "<MICROSOFT_ADS_ID>",
"columns": ["AccountName", "CurrencyCode", "Spend"], "aggregation": "Summary",
"time": {"CustomDateRangeStart": {"Year": 2026, "Month": 9, "Day": 1}, "CustomDateRangeEnd": {"Year": 2026, "Month": 9, "Day": 30},
"ReportTimeZone": "<ACCOUNT_TIME_ZONE>"}}
{"platform": "microsoft-ads", "action": "poll_report_status", "account_id": "<MICROSOFT_ADS_ID>", "report_request_id": "<REPORT_REQUEST_ID>"}
data_csv null with report_status Success means no spend in the month.
- Pinterest Ads (the last 90 days only; an older month comes from the user's export):
{"platform": "pinterest-ads", "action": "get_ad_account_analytics", "ad_account_id": "<PINTEREST_AD_ACCOUNT_ID>",
"start_date": "MONTH_START", "end_date": "MONTH_END", "granularity": "TOTAL", "columns": ["SPEND_IN_DOLLAR"]}
- Snapchat Ads. The bounds must be the account's own midnight written in UTC.
2026-09-01T00:00:00.000Zon a Los Angeles account covers 5 pm to 5 pm local time, not the calendar month;2026-09-01T07:00:00.000Zto2026-10-01T07:00:00.000Zcovers September exactly. Check thestart_timeandend_timethe response echoes in local time.
{"platform": "snapchat-ads", "action": "get_adaccount_stats", "ad_account_id": "<SNAPCHAT_AD_ACCOUNT_ID>",
"fields": ["spend"], "granularity": "TOTAL",
"start_time": "<MONTH_START_LOCAL_MIDNIGHT_IN_UTC>", "end_time": "<NEXT_MONTH_START_LOCAL_MIDNIGHT_IN_UTC>"}
- OpenAI Ads:
{"platform": "openai-ads", "action": "get_ad_account_insights", "ad_account_id": "<OPENAI_AD_ACCOUNT_ID>",
"time_ranges": [{"type": "date_range", "since": "MONTH_START", "until": "MONTH_END"}], "time_granularity": "none",
"fields": ["ad_account.spend"]}
- X Ads:
get_active_entitieswithentityCAMPAIGNfor the month; when it lists campaigns,get_statswithentityCAMPAIGN,metric_groups["BILLING"], at most 20 ids and 7 days a call, added up over the month. - Any other platform (AppLovin, Amazon, Reddit and the like): from the user's export or invoice only. Never estimate it.
An empty list from any of these means no spend in the month, not an error. Name each account's currency and reporting day on its line.
3. Budget vs actual by line
For every plan line: variance = actual minus budget, and variance % = variance ÷ budget. Flag a line when the variance is beyond 10% and beyond 100 in the plan currency (the user can change both). A line with spend and no budget is "unplanned"; a line with bud
…(truncated)