@koda-sl/baker-cli 0.879.0 → 0.881.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +5 -1
  2. package/dist/{account-6EJ22A7X.js → account-AIW3XGWG.js} +2 -2
  3. package/dist/{account-assets-ZY4UYCHQ.js → account-assets-FJFPB7KD.js} +54 -46
  4. package/dist/account-assets-FJFPB7KD.js.map +1 -0
  5. package/dist/{account-level-Z4Z5PUA6.js → account-level-CB6I4X5W.js} +4 -4
  6. package/dist/{accounts-JILEWVP6.js → accounts-2USPMXA2.js} +2 -2
  7. package/dist/{activities-JHKNRR3M.js → activities-DYI25TF4.js} +21 -12
  8. package/dist/activities-DYI25TF4.js.map +1 -0
  9. package/dist/{ads-7NUK2UOG.js → ads-G3N76HWA.js} +27 -19
  10. package/dist/ads-G3N76HWA.js.map +1 -0
  11. package/dist/{ads-SWRPUDVK.js → ads-WERB3QK5.js} +2 -2
  12. package/dist/{adsets-JF3CBKOU.js → adsets-2HV6TJJP.js} +48 -30
  13. package/dist/adsets-2HV6TJJP.js.map +1 -0
  14. package/dist/{asset-writes-HXFRHFWF.js → asset-writes-ZOVD5O5X.js} +4 -4
  15. package/dist/{audience-writes-PT6RLJAK.js → audience-writes-36E6ECON.js} +29 -15
  16. package/dist/audience-writes-36E6ECON.js.map +1 -0
  17. package/dist/{audiences-G3PRPIY4.js → audiences-65JSGH4L.js} +27 -15
  18. package/dist/audiences-65JSGH4L.js.map +1 -0
  19. package/dist/{businesses-3N6CTZ2Q.js → businesses-5AEHP23G.js} +2 -2
  20. package/dist/{campaigns-FN56B6B7.js → campaigns-PP3MFPJR.js} +29 -18
  21. package/dist/campaigns-PP3MFPJR.js.map +1 -0
  22. package/dist/{catalogs-N2I2GNHS.js → catalogs-UYYPZRFW.js} +3 -3
  23. package/dist/{chunk-SNQKL66G.js → chunk-3F6AXSPB.js} +2 -2
  24. package/dist/{chunk-6MFVGM3F.js → chunk-AMCW2IG7.js} +14 -3
  25. package/dist/chunk-AMCW2IG7.js.map +1 -0
  26. package/dist/{chunk-6XXKYTD5.js → chunk-BRHYK4HQ.js} +2 -2
  27. package/dist/{chunk-2W6ILA5Z.js → chunk-LDL5VBBD.js} +87 -8
  28. package/dist/chunk-LDL5VBBD.js.map +1 -0
  29. package/dist/{chunk-JV6O52V6.js → chunk-ZGYIG6OM.js} +2 -2
  30. package/dist/cli.js +1 -1
  31. package/dist/{copy-writes-YXVKXBQC.js → copy-writes-TEJRR2W2.js} +4 -4
  32. package/dist/{creatives-3AQ3EEUL.js → creatives-ZYY5OF5U.js} +32 -19
  33. package/dist/creatives-ZYY5OF5U.js.map +1 -0
  34. package/dist/{custom-conversions-XNYZOJYY.js → custom-conversions-YQPOB2IR.js} +27 -15
  35. package/dist/custom-conversions-YQPOB2IR.js.map +1 -0
  36. package/dist/{draft-3P2XHRWX.js → draft-OHAOBGVP.js} +2 -2
  37. package/dist/{insights-VD4QINO7.js → insights-PBJODKMY.js} +129 -28
  38. package/dist/insights-PBJODKMY.js.map +1 -0
  39. package/dist/{instant-experiences-KCAH5ONN.js → instant-experiences-YXH2AHFI.js} +3 -3
  40. package/dist/{leads-HU4GA6T4.js → leads-IGOXMIEW.js} +3 -3
  41. package/dist/{media-NHO7QT2A.js → media-QOGVG6CU.js} +3 -3
  42. package/dist/{meta-SOPDFYYK.js → meta-RJH5COPE.js} +40 -40
  43. package/dist/{page-photos-6PRIPJJE.js → page-photos-P2XMKTVF.js} +3 -3
  44. package/dist/{pages-Q4W64A3N.js → pages-O7NXGSBG.js} +2 -2
  45. package/dist/{pixels-HOOILVHZ.js → pixels-I7S5N76B.js} +26 -12
  46. package/dist/pixels-I7S5N76B.js.map +1 -0
  47. package/dist/{preview-3TA3ILQ5.js → preview-5CK5INGO.js} +2 -2
  48. package/dist/{rule-writes-TKNWMP3S.js → rule-writes-MSMVQDQO.js} +3 -3
  49. package/dist/{rules-BNNJXDYI.js → rules-UEKJOZTV.js} +41 -24
  50. package/dist/rules-UEKJOZTV.js.map +1 -0
  51. package/dist/{shared-3C5ZX44Q.js → shared-PPAWDMRF.js} +16 -4
  52. package/dist/{studies-5YCUBVK5.js → studies-TIF7PYEB.js} +33 -16
  53. package/dist/studies-TIF7PYEB.js.map +1 -0
  54. package/dist/{study-writes-CD3D23LK.js → study-writes-RGKBOOJ6.js} +3 -3
  55. package/dist/{targeting-BNJVE7XS.js → targeting-YWOOD6YL.js} +3 -3
  56. package/dist/{videos-RS3G65UV.js → videos-OF6PAPP2.js} +2 -2
  57. package/dist/{write-commands-PD3BEWWZ.js → write-commands-REUTFNJ3.js} +7 -7
  58. package/package.json +1 -1
  59. package/dist/account-assets-ZY4UYCHQ.js.map +0 -1
  60. package/dist/activities-JHKNRR3M.js.map +0 -1
  61. package/dist/ads-7NUK2UOG.js.map +0 -1
  62. package/dist/adsets-JF3CBKOU.js.map +0 -1
  63. package/dist/audience-writes-PT6RLJAK.js.map +0 -1
  64. package/dist/audiences-G3PRPIY4.js.map +0 -1
  65. package/dist/campaigns-FN56B6B7.js.map +0 -1
  66. package/dist/chunk-2W6ILA5Z.js.map +0 -1
  67. package/dist/chunk-6MFVGM3F.js.map +0 -1
  68. package/dist/creatives-3AQ3EEUL.js.map +0 -1
  69. package/dist/custom-conversions-XNYZOJYY.js.map +0 -1
  70. package/dist/insights-VD4QINO7.js.map +0 -1
  71. package/dist/pixels-HOOILVHZ.js.map +0 -1
  72. package/dist/rules-BNNJXDYI.js.map +0 -1
  73. package/dist/studies-5YCUBVK5.js.map +0 -1
  74. /package/dist/{account-6EJ22A7X.js.map → account-AIW3XGWG.js.map} +0 -0
  75. /package/dist/{account-level-Z4Z5PUA6.js.map → account-level-CB6I4X5W.js.map} +0 -0
  76. /package/dist/{accounts-JILEWVP6.js.map → accounts-2USPMXA2.js.map} +0 -0
  77. /package/dist/{ads-SWRPUDVK.js.map → ads-WERB3QK5.js.map} +0 -0
  78. /package/dist/{asset-writes-HXFRHFWF.js.map → asset-writes-ZOVD5O5X.js.map} +0 -0
  79. /package/dist/{businesses-3N6CTZ2Q.js.map → businesses-5AEHP23G.js.map} +0 -0
  80. /package/dist/{catalogs-N2I2GNHS.js.map → catalogs-UYYPZRFW.js.map} +0 -0
  81. /package/dist/{chunk-SNQKL66G.js.map → chunk-3F6AXSPB.js.map} +0 -0
  82. /package/dist/{chunk-6XXKYTD5.js.map → chunk-BRHYK4HQ.js.map} +0 -0
  83. /package/dist/{chunk-JV6O52V6.js.map → chunk-ZGYIG6OM.js.map} +0 -0
  84. /package/dist/{copy-writes-YXVKXBQC.js.map → copy-writes-TEJRR2W2.js.map} +0 -0
  85. /package/dist/{draft-3P2XHRWX.js.map → draft-OHAOBGVP.js.map} +0 -0
  86. /package/dist/{instant-experiences-KCAH5ONN.js.map → instant-experiences-YXH2AHFI.js.map} +0 -0
  87. /package/dist/{leads-HU4GA6T4.js.map → leads-IGOXMIEW.js.map} +0 -0
  88. /package/dist/{media-NHO7QT2A.js.map → media-QOGVG6CU.js.map} +0 -0
  89. /package/dist/{meta-SOPDFYYK.js.map → meta-RJH5COPE.js.map} +0 -0
  90. /package/dist/{page-photos-6PRIPJJE.js.map → page-photos-P2XMKTVF.js.map} +0 -0
  91. /package/dist/{pages-Q4W64A3N.js.map → pages-O7NXGSBG.js.map} +0 -0
  92. /package/dist/{preview-3TA3ILQ5.js.map → preview-5CK5INGO.js.map} +0 -0
  93. /package/dist/{rule-writes-TKNWMP3S.js.map → rule-writes-MSMVQDQO.js.map} +0 -0
  94. /package/dist/{shared-3C5ZX44Q.js.map → shared-PPAWDMRF.js.map} +0 -0
  95. /package/dist/{study-writes-CD3D23LK.js.map → study-writes-RGKBOOJ6.js.map} +0 -0
  96. /package/dist/{targeting-BNJVE7XS.js.map → targeting-YWOOD6YL.js.map} +0 -0
  97. /package/dist/{videos-RS3G65UV.js.map → videos-OF6PAPP2.js.map} +0 -0
  98. /package/dist/{write-commands-PD3BEWWZ.js.map → write-commands-REUTFNJ3.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/meta/custom-conversions.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { registerSchema } from \"../../../schemas.ts\";\nimport { writeAdsOutput, writeJsonEnvelope } from \"../output.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n listingLimit,\n readEachAccount,\n withAccountColumn,\n} from \"./shared.ts\";\n\n/** A Custom Conversion as the backend returns it, rule already read back as a phrase. */\nexport interface MetaCustomConversion {\n id: string;\n name?: string;\n description?: string;\n custom_event_type?: string;\n event_source_type?: string;\n pixel?: { id?: string; name?: string };\n rule?: string;\n rule_summary?: string;\n default_conversion_value?: number;\n retention_days?: number;\n is_archived?: boolean;\n is_unavailable?: boolean;\n creation_time?: string;\n first_fired_time?: string;\n last_fired_time?: string;\n}\n\n/** What the caller needs to pick one. The raw rule and the timestamps sit behind --full. */\ninterface CompactCustomConversion {\n id: string;\n name?: string;\n custom_event_type?: string;\n counts?: string;\n pixel_id?: string;\n last_fired_time?: string;\n archived?: true;\n unavailable?: true;\n}\n\nexport function compactCustomConversion(row: MetaCustomConversion): CompactCustomConversion {\n return {\n id: row.id,\n name: row.name,\n custom_event_type: row.custom_event_type,\n counts: row.rule_summary,\n pixel_id: row.pixel?.id,\n last_fired_time: row.last_fired_time,\n ...(row.is_archived ? { archived: true as const } : {}),\n ...(row.is_unavailable ? { unavailable: true as const } : {}),\n };\n}\n\n/**\n * What to say about a listing, once.\n *\n * A conversion that has never fired is the one thing that reads as \"broken\" and\n * usually is not — Meta creates it counting nothing until the rule matches a\n * real event — while pointing an ad set at one is a real decision with a real\n * cost, because Meta cannot optimize toward an event it has never seen. Saying\n * so here is cheaper than the chat where it gets discovered after a week of\n * delivery.\n */\nexport function customConversionHints(rows: MetaCustomConversion[]): string[] {\n if (rows.length === 0) {\n return [\n \"This account has no custom conversions. Optimize toward a standard pixel event instead (`--pixel-id` + `--custom-event-type`), or stage one: `baker ads meta custom-conversions create --name … --pixel-id … --custom-event-type LEAD --url-contains /thank-you`.\",\n ];\n }\n const hints: string[] = [\n \"To optimize an ad set toward one: `baker ads meta adsets create … --optimization-goal OFFSITE_CONVERSIONS --custom-conversion-id <id>`. Baker fills the pixel and the event category from the conversion — do not also pass --pixel-id or --custom-event-type.\",\n ];\n const neverFired = rows.filter((row) => !row.is_archived && !row.last_fired_time);\n if (neverFired.length > 0) {\n hints.push(\n `${neverFired.length === 1 ? \"This conversion has\" : `${neverFired.length} of these have`} never fired (${neverFired\n .map((row) => row.name ?? row.id)\n .join(\n \", \",\n )}). Meta cannot optimize toward an event it has never seen, so an ad set pointed at one delivers without learning — check the rule matches a page the site actually serves before spending on it.`,\n );\n }\n return hints;\n}\n\nregisterSchema({\n command: \"ads.meta.custom-conversions\",\n description:\n \"List the Custom Conversions defined on a Meta ad account — the measurement objects a marketer sets up in Events Manager (a pixel event narrowed by a rule, e.g. 'PageView on /thank-you'). Start here whenever the user talks about their own conversions rather than a standard event: an ad set optimizes toward one with `adsets create --custom-conversion-id <id>`. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n args: {\n \"account-id\": { ...LISTING_ACCOUNT_ARG, required: false },\n full: { type: \"boolean\", description: \"Include the raw rule JSON, retention and creation times\", required: false },\n limit: { type: \"string\", description: \"Max rows\", required: false },\n \"no-cache\": { type: \"boolean\", description: \"Bypass the cache\", required: false },\n output: { type: \"string\", description: \"json|csv\", required: false, default: \"json\" },\n },\n});\n\nconst listArgs = {\n \"account-id\": LISTING_ACCOUNT_ARG,\n full: { type: \"boolean\", description: \"Include the raw rule JSON, retention and creation times\" },\n limit: { type: \"string\", description: \"Max rows\" },\n \"no-cache\": NO_CACHE_ARG,\n output: { type: \"string\", description: \"Output format: json|csv|jsonl|md\", default: \"json\" },\n} as const;\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List custom conversions. Runs by default when no subcommand is given. Example: baker ads meta custom-conversions --account-id act_123\",\n },\n args: listArgs,\n run: async ({ args }) => {\n const accounts = await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n if (args.limit) params.limit = args.limit as string;\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const read = await readEachAccount(\n accounts,\n (accountId) =>\n apiGet<MetaCustomConversion[]>(\"/api/ads/meta/custom-conversions\", { ...params, \"account-id\": accountId }),\n { limit: listingLimit(args, 200) },\n );\n const rows = read.rows;\n const data: Array<Record<string, unknown>> = withAccountColumn(\n args.full ? rows.map((row) => ({ ...row })) : rows.map((row) => ({ ...compactCustomConversion(row) })),\n read.accountOf,\n );\n const fmt = csvOrJson(args);\n if (fmt !== \"json\") {\n writeAdsOutput(data, fmt, undefined, read.hints);\n return;\n }\n writeJsonEnvelope({ ok: true, data, hints: [...read.hints, ...customConversionHints(rows)] });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const customConversionsCommand = defineCommand({\n meta: {\n name: \"custom-conversions\",\n description: `List the Custom Conversions on an ad account, or stage a new one — a pixel event narrowed by a rule, set up in Events Manager.\nUse this whenever the user says \"my conversions\" rather than naming a standard event: the id here is what an ad set optimizes toward.\n\nExamples:\n baker ads meta custom-conversions --account-id act_123\n baker ads meta custom-conversions --account-id act_123 --full # raw rule JSON\n baker ads meta custom-conversions create --name \"Lead formulario\" --pixel-id 9988 --custom-event-type LEAD --url-contains \"/gracias\"`,\n },\n subCommands: {\n list: listCommand,\n create: () => import(\"./write-commands.ts\").then((m) => m.customConversionsCreateCommand),\n update: () => import(\"./asset-writes.ts\").then((m) => m.customConversionsUpdateCommand),\n delete: () => import(\"./asset-writes.ts\").then((m) => m.customConversionsDeleteCommand),\n },\n // `args` stays even though the parent has no `run`: citty scans rawArgs for\n // the subcommand name using THIS command's arg defs. `default` (not `run`)\n // dispatches the bare invocation.\n args: listArgs,\n default: \"list\",\n});\n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A,EACF;AACF,CAAC;AAEM,IAAM,2BAA2B,cAAc;AAAA,EACpD,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf;AAAA,EACA,aAAa;AAAA,IACX,MAAM;AAAA,IACN,QAAQ,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,8BAA8B;AAAA,IACxF,QAAQ,MAAM,OAAO,4BAAmB,EAAE,KAAK,CAAC,MAAM,EAAE,8BAA8B;AAAA,IACtF,QAAQ,MAAM,OAAO,4BAAmB,EAAE,KAAK,CAAC,MAAM,EAAE,8BAA8B;AAAA,EACxF;AAAA;AAAA;AAAA;AAAA,EAIA,MAAM;AAAA,EACN,SAAS;AACX,CAAC;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  handleMetaError
3
- } from "./chunk-2W6ILA5Z.js";
3
+ } from "./chunk-LDL5VBBD.js";
4
4
  import {
5
5
  draftRefs,
6
6
  removeDraftRefs
@@ -346,4 +346,4 @@ var metaDraftCommand = defineCommand({
346
346
  export {
347
347
  metaDraftCommand
348
348
  };
349
- //# sourceMappingURL=draft-3P2XHRWX.js.map
349
+ //# sourceMappingURL=draft-OHAOBGVP.js.map
@@ -8,7 +8,7 @@ import {
8
8
  getDateRange,
9
9
  handleMetaError,
10
10
  todayIso
11
- } from "./chunk-2W6ILA5Z.js";
11
+ } from "./chunk-LDL5VBBD.js";
12
12
  import {
13
13
  campaignsAnswered,
14
14
  metaBreakdownSyncedHint,
@@ -123,26 +123,54 @@ function keepNamed(entries, wanted, folded) {
123
123
  }
124
124
  var WINDOW_KEY = /^(\d+)d_(click|view)$/;
125
125
  var UNADDITIVE_FIELD = /^cost_per_|_roas$|_ctr$|_avg_/;
126
- function withValue(field, entry) {
127
- if (entry.value !== void 0) return entry;
128
- if (UNADDITIVE_FIELD.test(field)) return { ...entry, value: null };
126
+ function windowSum(entry, windows) {
129
127
  const widest = /* @__PURE__ */ new Map();
130
128
  for (const [key, figure] of Object.entries(entry)) {
131
129
  const window = WINDOW_KEY.exec(key);
132
- if (!window || !Number.isFinite(Number(figure))) continue;
130
+ if (!window || windows && !windows.includes(key) || !Number.isFinite(Number(figure))) continue;
133
131
  const days = Number(window[1]);
134
132
  const seen = widest.get(window[2] ?? "");
135
133
  if (!seen || days > seen.days) widest.set(window[2] ?? "", { days, figure: Number(figure) });
136
134
  }
137
- const total = [...widest.values()].reduce((sum, { figure }) => sum + figure, 0);
138
- return { ...entry, value: String(round2(total)) };
135
+ return [...widest.values()].reduce((sum, { figure }) => sum + figure, 0);
136
+ }
137
+ function withValue(field, entry) {
138
+ if (entry.value !== void 0) return entry;
139
+ if (UNADDITIVE_FIELD.test(field)) return { ...entry, value: null };
140
+ return { ...entry, value: String(round2(windowSum(entry))) };
141
+ }
142
+ function attributionKeys(entry) {
143
+ return Object.keys(entry).filter((key) => key !== "action_type" && key !== "value" && !key.startsWith("action_"));
144
+ }
145
+ function readsInWindows(windows) {
146
+ if (windows.includes("default")) return false;
147
+ return windows.length === 1 || windows.every((window) => WINDOW_KEY.test(window));
148
+ }
149
+ function countIn(entry, windows) {
150
+ if (windows.every((window) => WINDOW_KEY.test(window))) return windowSum(entry, windows);
151
+ const figure = Number(entry[windows[0] ?? ""]);
152
+ return Number.isFinite(figure) ? figure : 0;
139
153
  }
140
- function withValues(row) {
154
+ function inWindows(field, entry, windows) {
155
+ if (attributionKeys(entry).length === 0) {
156
+ return { ...entry, ...Object.fromEntries(windows.map((window) => [window, null])), value: null };
157
+ }
158
+ const unadditive = UNADDITIVE_FIELD.test(field);
159
+ const figures = Object.fromEntries(windows.map((window) => [window, entry[window] ?? (unadditive ? null : "0")]));
160
+ const only = windows.length === 1 ? figures[windows[0] ?? ""] : null;
161
+ const value = unadditive ? only ?? null : String(round2(countIn(entry, windows)));
162
+ return { ...entry, ...figures, value };
163
+ }
164
+ function isWindowed(field, entries) {
165
+ return MIXED_ACTION_FIELDS.has(field) || /_roas$/.test(field) || entries.some((entry) => attributionKeys(entry).length > 0);
166
+ }
167
+ function withValues(row, windows) {
141
168
  return Object.fromEntries(
142
- Object.entries(row).map(([field, value]) => [
143
- field,
144
- isActionArray(value) ? value.map((entry) => withValue(field, entry)) : value
145
- ])
169
+ Object.entries(row).map(([field, value]) => {
170
+ if (!isActionArray(value)) return [field, value];
171
+ if (!windows || !isWindowed(field, value)) return [field, value.map((entry) => withValue(field, entry))];
172
+ return [field, value.map((entry) => inWindows(field, entry, windows))];
173
+ })
146
174
  );
147
175
  }
148
176
  function compactArray(field, entries, wanted, out) {
@@ -174,7 +202,8 @@ function rowDisagreements(row, wanted) {
174
202
  return familiesOf(value).flatMap((family) => {
175
203
  const canonical = canonicalType(family[0]?.action_type ?? "");
176
204
  const printed = wanted ? wanted.includes(canonical) : !isNoise(canonical);
177
- if (!printed || new Set(family.map((entry) => Number(entry.value))).size < 2) return [];
205
+ const known = family.filter((entry) => entry.value !== null);
206
+ if (!printed || new Set(known.map((entry) => Number(entry.value))).size < 2) return [];
178
207
  const label = columnOf(field, { ...family[0], action_type: canonical });
179
208
  const pick = pickOf(canonical, family);
180
209
  const counts = family.map((entry) => `${entry.action_type} ${String(entry.value)}`).join(", ");
@@ -186,10 +215,38 @@ function foldedList(folded) {
186
215
  if (folded.size === 0) return null;
187
216
  return [...folded.entries()].map(([canonical, raws]) => `${[...raws].join(", ")} \u2192 ${canonical}`).join("; ");
188
217
  }
218
+ function columnsWhere(rows, test) {
219
+ const found = /* @__PURE__ */ new Map();
220
+ for (const row of rows) {
221
+ for (const [field, value] of Object.entries(row)) {
222
+ if (!COUNT_FIELDS.has(field) || !isActionArray(value)) continue;
223
+ for (const entry of value.filter(test))
224
+ found.set(columnOf(field, entry), (found.get(columnOf(field, entry)) ?? 0) + 1);
225
+ }
226
+ }
227
+ return [...found.entries()].map(([column, count]) => `${column} (${count} ${count === 1 ? "row" : "rows"})`);
228
+ }
229
+ function windowHints(rows, windows) {
230
+ const asked = windows.join(",");
231
+ const outside = columnsWhere(
232
+ rows,
233
+ (entry) => entry.value !== null && Number(entry.value) === 0 && attributionKeys(entry).some((key) => !windows.includes(key) && Number(entry[key]) > 0)
234
+ );
235
+ const unsplit = columnsWhere(rows, (entry) => entry.value === null);
236
+ return [
237
+ ...outside.length === 0 ? [] : [
238
+ `Meta counted ${outside.join(", ")} only outside ${asked}, so each reads 0 on those rows: a real 0 in ${asked}, not a missing figure (Meta counted it in another window and none in ${asked}).`
239
+ ],
240
+ ...unsplit.length === 0 ? [] : [
241
+ `Meta sent ${unsplit.join(", ")} as one total with no ${asked} figure, so each reads null on those rows: its count in ${asked} is not known, not 0; --full keeps Meta's own value, its 7d_click,1d_view total.`
242
+ ]
243
+ ];
244
+ }
189
245
  function compactInsightsRows(rows, options) {
190
246
  const dropped = /* @__PURE__ */ new Set();
191
247
  const folded = /* @__PURE__ */ new Map();
192
- const valued = rows.map(withValues);
248
+ const windows = options.windows && readsInWindows(options.windows) ? options.windows : void 0;
249
+ const valued = rows.map((row) => withValues(row, windows));
193
250
  const compacted = valued.map(
194
251
  (row) => Object.fromEntries(
195
252
  Object.entries(row).map(([field, value]) => [
@@ -199,12 +256,28 @@ function compactInsightsRows(rows, options) {
199
256
  )
200
257
  );
201
258
  return {
202
- rows: compacted,
259
+ rows: windows ? compacted.map((row) => inAskedWindowsOnly(row, windows)) : compacted,
203
260
  dropped: [...dropped],
204
261
  folded: foldedList(folded),
205
- disagreements: disagreeingCounters(valued, options.actionTypes)
262
+ disagreements: disagreeingCounters(valued, options.actionTypes),
263
+ windowHints: windows ? windowHints(compacted, windows) : []
206
264
  };
207
265
  }
266
+ function inAskedWindowsOnly(row, windows) {
267
+ return Object.fromEntries(
268
+ Object.entries(row).map(([field, value]) => {
269
+ if (!isActionArray(value)) return [field, value];
270
+ return [
271
+ field,
272
+ value.map(
273
+ (entry) => Object.fromEntries(
274
+ Object.entries(entry).filter(([key]) => !attributionKeys(entry).includes(key) || windows.includes(key))
275
+ )
276
+ )
277
+ ];
278
+ })
279
+ );
280
+ }
208
281
  var COUNT_FIELDS = /* @__PURE__ */ new Set(["actions", "unique_actions", "conversions"]);
209
282
  var CUSTOM_EVENT_PREFIX = "offsite_conversion.fb_pixel_custom";
210
283
  function columnOf(field, entry) {
@@ -273,7 +346,9 @@ var RESULT_PRIORITY = [
273
346
  "add_to_cart"
274
347
  ];
275
348
  function countOf(actions, type) {
276
- return actions.filter((entry) => entry.action_type === type).reduce((sum, entry) => sum + Number(entry.value), 0);
349
+ const entries = actions.filter((entry) => entry.action_type === type);
350
+ if (entries.some((entry) => entry.value === null)) return null;
351
+ return entries.reduce((sum, entry) => sum + Number(entry.value), 0);
277
352
  }
278
353
  function resultTypeOf(actions, wanted) {
279
354
  const present = new Set(actions.map((entry) => entry.action_type));
@@ -295,7 +370,7 @@ function withFunnelResults(rows, options) {
295
370
  ...row,
296
371
  result_type: resultType,
297
372
  results,
298
- cvr: results !== null && linkClicks > 0 ? round2(results / linkClicks * 100) : null,
373
+ cvr: results !== null && linkClicks !== null && linkClicks > 0 ? round2(results / linkClicks * 100) : null,
299
374
  cost_per_result: results !== null && results > 0 && Number.isFinite(spend) ? round2(spend / results) : null
300
375
  };
301
376
  });
@@ -304,7 +379,10 @@ function withLeadCost(rows) {
304
379
  return rows.map((row) => {
305
380
  const leads = countOf(isActionArray(row.actions) ? row.actions : [], "lead");
306
381
  const spend = Number(row.spend);
307
- return { ...row, cost_per_lead: leads > 0 && Number.isFinite(spend) ? round2(spend / leads) : null };
382
+ return {
383
+ ...row,
384
+ cost_per_lead: leads !== null && leads > 0 && Number.isFinite(spend) ? round2(spend / leads) : null
385
+ };
308
386
  });
309
387
  }
310
388
  function withIntentFigures(rows, intents, options) {
@@ -854,8 +932,18 @@ function buildFiltering(args) {
854
932
  }
855
933
  function buildAttributionWindows(args) {
856
934
  const explicit = commaSplit(args["attribution-windows"]);
857
- if (explicit) return explicit;
858
- return DEFAULT_ATTRIBUTION_WINDOWS;
935
+ if (!explicit) return DEFAULT_ATTRIBUTION_WINDOWS;
936
+ const named = namedWindows(args);
937
+ if (args.full || !named || !named.every((window) => CLICK_OR_VIEW_WINDOW.test(window))) return explicit;
938
+ return [.../* @__PURE__ */ new Set([...explicit, ...DEFAULT_ATTRIBUTION_WINDOWS])];
939
+ }
940
+ var CLICK_OR_VIEW_WINDOW = /^\d+d_(click|view)$/;
941
+ function namedWindows(args) {
942
+ if (args["use-account-attribution"] || args["use-unified-attribution"]) return void 0;
943
+ const explicit = commaSplit(args["attribution-windows"]);
944
+ if (!explicit) return void 0;
945
+ const isDefault = explicit.length === 1 && explicit[0] === "default" || explicit.length === DEFAULT_ATTRIBUTION_WINDOWS.length && DEFAULT_ATTRIBUTION_WINDOWS.every((window) => explicit.includes(window));
946
+ return isDefault ? void 0 : explicit;
859
947
  }
860
948
  function buildBody(args) {
861
949
  const intents = intentsOf(args);
@@ -957,12 +1045,21 @@ function rowsToPrint(rows, body, args) {
957
1045
  function shapeRows(rows, args) {
958
1046
  if (args.full) return { rows, hints: [] };
959
1047
  const actionTypes = actionTypesOf(args);
960
- const { rows: compacted, dropped, folded, disagreements } = compactInsightsRows(rows, { actionTypes });
1048
+ const {
1049
+ rows: compacted,
1050
+ dropped,
1051
+ folded,
1052
+ disagreements,
1053
+ windowHints: windowHints2
1054
+ } = compactInsightsRows(rows, {
1055
+ actionTypes,
1056
+ windows: namedWindows(args)
1057
+ });
961
1058
  const compact = withIntentFigures(compacted, intentsOf(args), { actionTypes });
962
1059
  const foldHints = folded === null ? [] : [
963
1060
  `Meta's other names for one conversion print under its plain name (${folded}); read it by that name, or --action-types <raw name> keeps Meta's own name in actions, conversions and their values and costs.`
964
1061
  ];
965
- if (dropped.length === 0) return { rows: compact, hints: [...foldHints, ...disagreements] };
1062
+ if (dropped.length === 0) return { rows: compact, hints: [...foldHints, ...disagreements, ...windowHints2] };
966
1063
  const named = dropped.slice(0, 4).join(", ");
967
1064
  const more = dropped.length > 4 ? ` and ${dropped.length - 4} more` : "";
968
1065
  return {
@@ -970,7 +1067,8 @@ function shapeRows(rows, args) {
970
1067
  hints: [
971
1068
  `Engagement and combined action types were left out (${named}${more}); --action-types <type> keeps one, --full returns every raw action.`,
972
1069
  ...foldHints,
973
- ...disagreements
1070
+ ...disagreements,
1071
+ ...windowHints2
974
1072
  ]
975
1073
  };
976
1074
  }
@@ -1022,11 +1120,11 @@ async function printCompared(input) {
1022
1120
  const previousPeriod2 = input.windows.length === 1 && input.windows[0]?.label === "previous_period";
1023
1121
  const synced = syncedHintOf(body, input.rows, previousPeriod2);
1024
1122
  const ownHints = new Set(input.printed.hints);
1025
- const windowHints = windows.flatMap(
1123
+ const windowHints2 = windows.flatMap(
1026
1124
  (window) => window.hints.filter((hint) => !ownHints.has(hint.slice(window.label.length + 2)))
1027
1125
  );
1028
1126
  const lead = synced === null ? [] : [synced];
1029
- const hints = [...input.printed.hints, ...windowHints, ...compared.hints];
1127
+ const hints = [...input.printed.hints, ...windowHints2, ...compared.hints];
1030
1128
  if (input.fmt === "json") {
1031
1129
  writeInsightsJson(compared.rows, lead, [...placementDeliveryHints(input.rows), ...hints]);
1032
1130
  return;
@@ -1109,6 +1207,9 @@ Action arrays (actions, cost_per_action_type, conversions, \u2026) are compact:
1109
1207
  (omni_, offsite_conversion.fb_pixel_, onsite_web_ \u2026) collapse to one entry under its plain name
1110
1208
  (complete_registration, lead, purchase), and engagement counts (likes, saves, video views) are left out. Every
1111
1209
  entry has a value: when Meta sent none, a count's window figures summed, else 0; a cost, ROAS or rate says null.
1210
+ --attribution-windows other than the default (7d_click for click-only) makes value those windows alone, every named
1211
+ window set (0 where Meta counted none, null where it sent one total it did not split): Meta's own value, kept by
1212
+ --full, is its 7d_click,1d_view total whatever was asked.
1112
1213
  --action-types keeps only the named types; --full returns Meta's raw arrays. --output md|csv gives each
1113
1214
  action type its own column (actions.lead, cost_per_action_type.lead); a custom event, or every type --action-types
1114
1215
  names, also gets its cost (cost_per.conversions.<type> = spend / count). --intent funnel adds result_type, results,
@@ -1157,7 +1258,7 @@ Async is automatic for heavy queries; pass --async to force it, or --no-async to
1157
1258
  "include-undelivered": { type: "boolean", description: "Keep rows where impressions=0 (off by default)" },
1158
1259
  "attribution-windows": {
1159
1260
  type: "string",
1160
- description: "Override default 7d_click,1d_view (only 1d_view, 1d_click, 7d_click, 28d_click work post Jan 2026)"
1261
+ description: "Override default 7d_click,1d_view (only 1d_view, 1d_click, 7d_click, 28d_click work post Jan 2026). Start here for click-only: --attribution-windows 7d_click \u2014 each compact value then counts the named windows alone, each window key set (0 where Meta counted none, null where it did not split its total)."
1161
1262
  },
1162
1263
  "use-account-attribution": { type: "boolean", description: "Use account-saved attribution setting" },
1163
1264
  "use-unified-attribution": { type: "boolean", description: "Use ad-set unified attribution setting" },
@@ -1224,4 +1325,4 @@ export {
1224
1325
  insightsCommand,
1225
1326
  wantsAsync
1226
1327
  };
1227
- //# sourceMappingURL=insights-VD4QINO7.js.map
1328
+ //# sourceMappingURL=insights-PBJODKMY.js.map