Fix live reports: Graph adapter + selectable backend (graph | social-cli)#8
Open
TheMattBerman wants to merge 2 commits into
Open
Fix live reports: Graph adapter + selectable backend (graph | social-cli)#8TheMattBerman wants to merge 2 commits into
TheMattBerman wants to merge 2 commits into
Conversation
…k mode
The report layer's jq targets an internal schema (account_summary,
campaign_insights[], ad_insights[], ad_daily[], today_campaign_spend[]) that
only the mock fixtures produced. The non-mock path piped raw responses straight
through, so every report (pacing, overview, winners, bleeders, fatigue) errored
against the live API — the kit effectively only ran in mock.
- scripts/lib/live-adapter.sh: pure transform (mk_assemble_insights) from raw
Graph responses -> internal schema, plus a thin fetch layer (mk_build_live_insights)
and campaign-list normalizer. Uses the Marketing API for level=campaign/level=ad
breakdowns because the official Ads CLI `insights get` is account-level only.
Memoized per process; rounds ctr/cpc/freq to 2dp; follows paging.
- scripts/lib/meta-cli.sh: route insights ops through the adapter; normalize the
CLI campaign list into {data:[{id,name,status}]}.
- scripts/lib/config.sh: .env no longer clobbers variables already set on the
command line, so `META_KIT_MODE=mock ./run.sh` reliably forces mock.
- scripts/test/: offline unit tests for the transform (23 assertions, synthetic
raw-shape fixtures — no client data, no network).
- docs: README/SETUP/.env.example document the Graph API insights path,
GRAPH_API_VERSION, the env-precedence rule, and the multi-brand patterns.
Verified live (read-only) against two real accounts; mock mode unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…l-cli)
social-cli (@vishalgojha/social-cli) was the kit's ORIGINAL engine and natively
supports `marketing insights --level campaign|ad --time-increment` plus mutations
and OAuth. The migration to the official Ads CLI is what dropped --level and broke
live reports. This brings the richer engine back as an opt-in, alongside the
zero-dependency Graph backend.
- scripts/lib/config.sh: mk_backend() reads META_KIT_BACKEND (default graph).
- scripts/lib/backend-social.sh: social-cli fetch layer — preamble stripper,
--export-based insights (clean JSON), flat-array -> {data:[...]} wrapping so it
reuses the SAME pure transform (mk_assemble_insights) as graph. Campaign-list
+ status + level insights wired; pacing target is campaign-budget-based
(social has no account-level adsets edge — documented).
- scripts/lib/live-adapter.sh: mk_build_live_insights dispatches by backend;
graph fetch extracted to mk_fetch_bundle_graph.
- scripts/lib/meta-cli.sh: campaign-list routes by backend; doctor reports
backend + social-cli presence/version.
- scripts/test/test_social_backend.sh: 10 offline assertions (preamble strip,
normalize, social arrays -> shared transform). Graph suite still 23/23.
- docs: README/SETUP/.env.example document both backends, the install/auth for
social-cli, the speed trade-off, and the pacing-target caveat.
Verified live (read-only) on a real ad account: both backends produce identical
spend/winners/bleeders/fatigue. Fixed a recurrence of the "${var:-{}}" brace bug
in the social account-meta path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every report worked in mock mode but errored against the live API. The report layer's
jqtargets an internal schema (account_summary,campaign_insights[],ad_insights[],ad_daily[],today_campaign_spend[]) that only the mock fixtures produced; the non-mock path piped raw API responses straight through. Root cause: the official Ads CLI'sinsights getis account-level only (no--level), so it can't return per-campaign/per-ad rows — and the kit's earlier migration to that CLI is what dropped the--levelsupport its reports depend on.Fix
1. Graph API insights adapter (
scripts/lib/live-adapter.sh)mk_assemble_insights) from raw API responses → the kit's internal schema.level=campaign/level=ad(one call each — scales past hundreds of ads). Memoized per run, paginated, rounds ctr/cpc/freq.metaCLI, normalized to{data:[...]}.2. Selectable backend (
META_KIT_BACKEND)graph(default) — direct Marketing API viacurl. Fast, zero extra deps.social-cli—@vishalgojha/social-cli, the kit's original engine: native--levelinsights, mutations, OAuth. Slower (async report jobs).scripts/lib/backend-social.shstrips social-cli's stdout preamble and uses--exportfor clean JSON.3. Env precedence fix (
scripts/lib/config.sh).envno longer clobbers variables already set on the command line, soMETA_KIT_MODE=mock ./run.sh …reliably forces mock (the documented override was previously silently broken when.envexisted).Tests
scripts/test/test_live_adapter.sh— 23 offline assertions (transform → schema, rounding, report render).scripts/test/test_social_backend.sh— 10 offline assertions (preamble strip, normalize, social arrays → shared transform).Notes
🤖 Generated with Claude Code