siluzan-tso-cli 1.1.67-beta.2 → 1.1.67
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.
- package/README.md +1 -2
- package/dist/index.js +1390 -134
- package/dist/skill/SKILL.md +4 -2
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/references/README.md +3 -0
- package/dist/skill/references/accounts/accounts-list.md +1 -1
- package/dist/skill/references/accounts/accounts-permissions.md +2 -2
- package/dist/skill/references/accounts/finance.md +1 -1
- package/dist/skill/references/accounts/open-account-by-media.md +1 -1
- package/dist/skill/references/accounts/open-account-google-ui.md +1 -1
- package/dist/skill/references/analytics/rag.md +1 -1
- package/dist/skill/references/analytics/reporting.md +5 -5
- package/dist/skill/references/core/setup.md +5 -5
- package/dist/skill/references/core/workflows.md +2 -2
- package/dist/skill/references/google-ads/demand-gen-api.md +1 -1
- package/dist/skill/references/google-ads/google-ads-exclusions.md +62 -0
- package/dist/skill/references/google-ads/google-ads-protection.md +70 -0
- package/dist/skill/references/google-ads/google-ads-read.md +4 -0
- package/dist/skill/references/google-ads/google-ads-write.md +3 -1
- package/dist/skill/references/google-ads/google-ads.md +3 -1
- package/dist/skill/references/google-ads/rules/google-ads-campaign-optimization.md +1 -1
- package/dist/skill/references/google-ads/rules/google-ads-keyword-optimization.md +1 -1
- package/dist/skill/references/google-ads/rules/google-ads-keyword-strategy.md +1 -1
- package/dist/skill/references/google-ads/rules/google-ads-pmax-guide.md +10 -10
- package/dist/skill/references/misc/tso-home.md +2 -2
- package/dist/skill/scripts/install.ps1 +3 -3
- package/dist/skill/scripts/install.sh +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2397,7 +2397,7 @@ function rawRequest(url, options) {
|
|
|
2397
2397
|
stream = res.pipe(zlib.createBrotliDecompress());
|
|
2398
2398
|
}
|
|
2399
2399
|
let failed = false;
|
|
2400
|
-
const
|
|
2400
|
+
const fail7 = (err) => {
|
|
2401
2401
|
if (failed) return;
|
|
2402
2402
|
failed = true;
|
|
2403
2403
|
res.destroy();
|
|
@@ -2416,7 +2416,7 @@ function rawRequest(url, options) {
|
|
|
2416
2416
|
reject(err);
|
|
2417
2417
|
};
|
|
2418
2418
|
const onStreamError = (err) => {
|
|
2419
|
-
|
|
2419
|
+
fail7(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
|
|
2420
2420
|
};
|
|
2421
2421
|
if (stream !== res) stream.on("error", onStreamError);
|
|
2422
2422
|
res.on("error", onStreamError);
|
|
@@ -2427,7 +2427,7 @@ function rawRequest(url, options) {
|
|
|
2427
2427
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
2428
2428
|
byteLen += buf.length;
|
|
2429
2429
|
if (maxBytes > 0 && byteLen > maxBytes) {
|
|
2430
|
-
|
|
2430
|
+
fail7(
|
|
2431
2431
|
new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
|
|
2432
2432
|
);
|
|
2433
2433
|
return;
|
|
@@ -2540,15 +2540,15 @@ function messageFromJsonValue(value) {
|
|
|
2540
2540
|
const rec = value;
|
|
2541
2541
|
if (rec.errors && typeof rec.errors === "object" && !Array.isArray(rec.errors)) {
|
|
2542
2542
|
const msgs = [];
|
|
2543
|
-
for (const [
|
|
2543
|
+
for (const [field5, raw] of Object.entries(rec.errors)) {
|
|
2544
2544
|
if (Array.isArray(raw)) {
|
|
2545
2545
|
for (const item of raw) {
|
|
2546
2546
|
const msg = messageFromJsonValue(item);
|
|
2547
|
-
if (msg) msgs.push(`${
|
|
2547
|
+
if (msg) msgs.push(`${field5}: ${msg}`);
|
|
2548
2548
|
}
|
|
2549
2549
|
} else {
|
|
2550
2550
|
const msg = messageFromJsonValue(raw);
|
|
2551
|
-
if (msg) msgs.push(`${
|
|
2551
|
+
if (msg) msgs.push(`${field5}: ${msg}`);
|
|
2552
2552
|
}
|
|
2553
2553
|
}
|
|
2554
2554
|
if (msgs.length > 0) return msgs.join("; ");
|
|
@@ -4104,7 +4104,7 @@ var DEFAULT_API_BASE;
|
|
|
4104
4104
|
var init_defaults = __esm({
|
|
4105
4105
|
"src/config/defaults.ts"() {
|
|
4106
4106
|
"use strict";
|
|
4107
|
-
DEFAULT_API_BASE = "https://tso-api
|
|
4107
|
+
DEFAULT_API_BASE = "https://tso-api.siluzan.com";
|
|
4108
4108
|
}
|
|
4109
4109
|
});
|
|
4110
4110
|
|
|
@@ -5980,7 +5980,7 @@ function htmlLangAttr(lang) {
|
|
|
5980
5980
|
return lang === "en" ? "en" : "zh-CN";
|
|
5981
5981
|
}
|
|
5982
5982
|
function stampMetaLang(payload, lang) {
|
|
5983
|
-
const prev = payload.meta;
|
|
5983
|
+
const prev = "meta" in payload ? payload.meta : void 0;
|
|
5984
5984
|
const meta = prev && typeof prev === "object" && !Array.isArray(prev) ? { ...prev, lang } : { lang };
|
|
5985
5985
|
return { ...payload, meta };
|
|
5986
5986
|
}
|
|
@@ -9326,8 +9326,8 @@ var init_http_retry = __esm({
|
|
|
9326
9326
|
});
|
|
9327
9327
|
|
|
9328
9328
|
// src/commands/google-analysis/normalize-impression-shares.ts
|
|
9329
|
-
function normalizeShareValue(value, competitiveMetrics,
|
|
9330
|
-
const cmVal = competitiveMetrics?.[
|
|
9329
|
+
function normalizeShareValue(value, competitiveMetrics, field5) {
|
|
9330
|
+
const cmVal = competitiveMetrics?.[field5];
|
|
9331
9331
|
if (typeof cmVal === "number" && Number.isFinite(cmVal)) {
|
|
9332
9332
|
return cmVal;
|
|
9333
9333
|
}
|
|
@@ -9339,10 +9339,10 @@ function normalizeShareValue(value, competitiveMetrics, field) {
|
|
|
9339
9339
|
function normalizeLegacyShareOnRow(row) {
|
|
9340
9340
|
const rawCm = row.competitiveMetrics;
|
|
9341
9341
|
const competitiveMetrics = rawCm !== null && typeof rawCm === "object" && !Array.isArray(rawCm) ? rawCm : null;
|
|
9342
|
-
for (const
|
|
9343
|
-
const v = row[
|
|
9342
|
+
for (const field5 of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
|
|
9343
|
+
const v = row[field5];
|
|
9344
9344
|
if (typeof v !== "number" || !Number.isFinite(v)) continue;
|
|
9345
|
-
row[
|
|
9345
|
+
row[field5] = normalizeShareValue(v, competitiveMetrics, field5);
|
|
9346
9346
|
}
|
|
9347
9347
|
}
|
|
9348
9348
|
function normalizeRowsInArray(rows) {
|
|
@@ -106008,7 +106008,7 @@ function num6(value) {
|
|
|
106008
106008
|
function round26(value) {
|
|
106009
106009
|
return Math.round(value * 100) / 100;
|
|
106010
106010
|
}
|
|
106011
|
-
function
|
|
106011
|
+
function money2(value) {
|
|
106012
106012
|
return round26(num6(value) ?? 0);
|
|
106013
106013
|
}
|
|
106014
106014
|
function count(value) {
|
|
@@ -106126,15 +106126,15 @@ function campaignRows(data) {
|
|
|
106126
106126
|
conv += pair.conv;
|
|
106127
106127
|
return [
|
|
106128
106128
|
str(row.campaignName),
|
|
106129
|
-
|
|
106130
|
-
|
|
106129
|
+
money2(row.budgetAmountYuan),
|
|
106130
|
+
money2(row.spend),
|
|
106131
106131
|
count(row.impressions),
|
|
106132
106132
|
count(row.clicks),
|
|
106133
106133
|
rate(row.ctr),
|
|
106134
|
-
|
|
106134
|
+
money2(row.averageCpc),
|
|
106135
106135
|
count(pair.all),
|
|
106136
106136
|
count(pair.conv),
|
|
106137
|
-
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" :
|
|
106137
|
+
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
|
|
106138
106138
|
rate(row.conversionRate)
|
|
106139
106139
|
];
|
|
106140
106140
|
});
|
|
@@ -106162,13 +106162,13 @@ function keywordRows(data, lang = "zh") {
|
|
|
106162
106162
|
str(matchOf(row)),
|
|
106163
106163
|
str(row.campaignName),
|
|
106164
106164
|
str(row.adGroupName),
|
|
106165
|
-
|
|
106165
|
+
money2(row.spend),
|
|
106166
106166
|
count(row.impressions),
|
|
106167
106167
|
count(row.clicks),
|
|
106168
106168
|
rate(row.ctr),
|
|
106169
|
-
|
|
106169
|
+
money2(row.averageCpc),
|
|
106170
106170
|
count(row.conversions),
|
|
106171
|
-
num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" :
|
|
106171
|
+
num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money2(row.costPerConversion),
|
|
106172
106172
|
rate(row.conversionRate)
|
|
106173
106173
|
]);
|
|
106174
106174
|
}
|
|
@@ -106186,10 +106186,10 @@ function searchTermRows(data, lang = "zh") {
|
|
|
106186
106186
|
count(row.impressions),
|
|
106187
106187
|
count(row.clicks),
|
|
106188
106188
|
rate(row.ctr),
|
|
106189
|
-
|
|
106190
|
-
|
|
106189
|
+
money2(row.averageCpc),
|
|
106190
|
+
money2(row.spend),
|
|
106191
106191
|
count(row.conversions),
|
|
106192
|
-
num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" :
|
|
106192
|
+
num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money2(row.costPerConversion),
|
|
106193
106193
|
rate(row.conversionRate)
|
|
106194
106194
|
]);
|
|
106195
106195
|
}
|
|
@@ -106204,11 +106204,11 @@ function deviceRows(data, lang = "zh") {
|
|
|
106204
106204
|
count(row.impressions),
|
|
106205
106205
|
count(row.clicks),
|
|
106206
106206
|
rate(row.ctr),
|
|
106207
|
-
|
|
106208
|
-
|
|
106207
|
+
money2(row.averageCpc),
|
|
106208
|
+
money2(row.spend),
|
|
106209
106209
|
count(pair.all),
|
|
106210
106210
|
count(pair.conv),
|
|
106211
|
-
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" :
|
|
106211
|
+
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
|
|
106212
106212
|
rate(row.conversionRate)
|
|
106213
106213
|
];
|
|
106214
106214
|
});
|
|
@@ -106226,13 +106226,13 @@ function geoRows(data, lang = "zh") {
|
|
|
106226
106226
|
count(row.impressions),
|
|
106227
106227
|
interactions > 0 ? count(interactions) : 0,
|
|
106228
106228
|
interactionRateOf(row, impressions, interactions),
|
|
106229
|
-
|
|
106229
|
+
money2(row.spend),
|
|
106230
106230
|
dashOrMoney(num6(row.spend) ?? 0, interactions),
|
|
106231
106231
|
count(row.clicks),
|
|
106232
106232
|
rate(row.ctr),
|
|
106233
106233
|
count(pair.all),
|
|
106234
106234
|
count(pair.conv),
|
|
106235
|
-
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" :
|
|
106235
|
+
num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
|
|
106236
106236
|
rate(row.conversionRate)
|
|
106237
106237
|
];
|
|
106238
106238
|
});
|
|
@@ -107223,8 +107223,8 @@ var init_batch_runner = __esm({
|
|
|
107223
107223
|
shouldDowngrade(now = Date.now()) {
|
|
107224
107224
|
if (this.window.length < this.opts.windowSize) return false;
|
|
107225
107225
|
if (now - this.lastDowngradeAt < this.opts.cooldownMs) return false;
|
|
107226
|
-
const
|
|
107227
|
-
const rate2 =
|
|
107226
|
+
const fail7 = this.window.filter((s) => !s).length;
|
|
107227
|
+
const rate2 = fail7 / this.window.length;
|
|
107228
107228
|
if (rate2 >= this.opts.errorRateThreshold) {
|
|
107229
107229
|
this.lastDowngradeAt = now;
|
|
107230
107230
|
this.window.length = 0;
|
|
@@ -112481,8 +112481,8 @@ function assertReportPushMedia(media) {
|
|
|
112481
112481
|
process.exit(1);
|
|
112482
112482
|
}
|
|
112483
112483
|
}
|
|
112484
|
-
function formatReportPushHistoryDate(
|
|
112485
|
-
const t =
|
|
112484
|
+
function formatReportPushHistoryDate(isoDate3) {
|
|
112485
|
+
const t = isoDate3.trim();
|
|
112486
112486
|
if (!t) return "";
|
|
112487
112487
|
if (t.includes("T") && t.includes("+")) return t;
|
|
112488
112488
|
if (t.includes("T")) return `${t}+08:00`;
|
|
@@ -116017,10 +116017,10 @@ function biddingStrategiesMatch(expected, actual) {
|
|
|
116017
116017
|
const act = String(actual ?? "").trim().toUpperCase();
|
|
116018
116018
|
return exp === "TARGET_CPA" && act === "MAXIMIZE_CONVERSIONS" || exp === "TARGET_ROAS" && act === "MAXIMIZE_CONVERSION_VALUE";
|
|
116019
116019
|
}
|
|
116020
|
-
function fieldCheck(
|
|
116021
|
-
if (!present) return { field, expected, actual: void 0, state: "unread" };
|
|
116020
|
+
function fieldCheck(field5, expected, actual, present) {
|
|
116021
|
+
if (!present) return { field: field5, expected, actual: void 0, state: "unread" };
|
|
116022
116022
|
return {
|
|
116023
|
-
field,
|
|
116023
|
+
field: field5,
|
|
116024
116024
|
expected,
|
|
116025
116025
|
actual,
|
|
116026
116026
|
state: sameWriteValue(expected, actual) ? "match" : "mismatch"
|
|
@@ -116063,10 +116063,10 @@ function readKey(obj, keys) {
|
|
|
116063
116063
|
function evaluateCampaignReadback(after, expected, readFailed) {
|
|
116064
116064
|
if (readFailed || !after) return { verification: "unknown", checks: [] };
|
|
116065
116065
|
const checks = [];
|
|
116066
|
-
const push = (
|
|
116066
|
+
const push = (field5, expectedValue, keys) => {
|
|
116067
116067
|
if (expectedValue === void 0) return;
|
|
116068
116068
|
const found = readKey(after, keys);
|
|
116069
|
-
checks.push(fieldCheck(
|
|
116069
|
+
checks.push(fieldCheck(field5, expectedValue, found.value, found.present));
|
|
116070
116070
|
};
|
|
116071
116071
|
push("name", expected.name, ["name", "Name"]);
|
|
116072
116072
|
push("statusV2", expected.statusV2, ["statusV2", "StatusV2"]);
|
|
@@ -116326,6 +116326,20 @@ function keywordRowToYuan(item) {
|
|
|
116326
116326
|
if (rawMaxCpc == null) return item;
|
|
116327
116327
|
return { ...rest, maxCPCYuan: toDisplayMoney(rawMaxCpc) };
|
|
116328
116328
|
}
|
|
116329
|
+
function keywordApprovalCell(item) {
|
|
116330
|
+
const status = String(item["approvalStatusV2"] ?? item["ApprovalStatusV2"] ?? "").trim();
|
|
116331
|
+
return status || "\u2014";
|
|
116332
|
+
}
|
|
116333
|
+
function keywordDisapprovalReasons(item) {
|
|
116334
|
+
const raw = item["disapprovalReasons"] ?? item["DisapprovalReasons"];
|
|
116335
|
+
if (Array.isArray(raw)) {
|
|
116336
|
+
return raw.map((part) => String(part).trim()).filter(Boolean);
|
|
116337
|
+
}
|
|
116338
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
116339
|
+
return raw.split(/[;;]/).map((part) => part.trim()).filter(Boolean);
|
|
116340
|
+
}
|
|
116341
|
+
return [];
|
|
116342
|
+
}
|
|
116329
116343
|
async function runAdKeywords(opts) {
|
|
116330
116344
|
opts = withResolvedAdAccount(opts);
|
|
116331
116345
|
const config = loadConfig(opts.token);
|
|
@@ -116417,6 +116431,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
|
|
|
116417
116431
|
{ key: "campaign", header: "\u5E7F\u544A\u7CFB\u5217" },
|
|
116418
116432
|
{ key: "adGroup", header: "\u5E7F\u544A\u7EC4" },
|
|
116419
116433
|
{ key: "status", header: "\u72B6\u6001" },
|
|
116434
|
+
{ key: "approval", header: "\u5BA1\u6838" },
|
|
116420
116435
|
{ key: "matchType", header: "\u5339\u914D\u7C7B\u578B" },
|
|
116421
116436
|
{ key: "impressions", header: "\u5C55\u793A" },
|
|
116422
116437
|
{ key: "clicks", header: "\u70B9\u51FB" },
|
|
@@ -116430,6 +116445,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
|
|
|
116430
116445
|
const adGroup = String(item["adGroupName"] ?? item["adGroup"] ?? "");
|
|
116431
116446
|
const status = String(item["userStatus"] ?? "");
|
|
116432
116447
|
const matchType = String(item["matchTypeV2"] ?? "");
|
|
116448
|
+
const approval = keywordApprovalCell(item);
|
|
116433
116449
|
const ctr = item["ctr"] != null ? (Number(item["ctr"]) * 100).toFixed(2) + "%" : "\u2014";
|
|
116434
116450
|
const spend = item["spend"] != null ? Number(item["spend"]).toFixed(2) : "\u2014";
|
|
116435
116451
|
const valueRaw = item["conversionsValue"];
|
|
@@ -116439,6 +116455,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
|
|
|
116439
116455
|
campaign: campaign.slice(0, campW),
|
|
116440
116456
|
adGroup: adGroup.slice(0, grpW),
|
|
116441
116457
|
status,
|
|
116458
|
+
approval,
|
|
116442
116459
|
matchType,
|
|
116443
116460
|
impressions: String(item["impressions"] ?? 0),
|
|
116444
116461
|
clicks: String(item["clicks"] ?? 0),
|
|
@@ -116448,6 +116465,12 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
|
|
|
116448
116465
|
};
|
|
116449
116466
|
});
|
|
116450
116467
|
printCliTable(rows, cols);
|
|
116468
|
+
items3.forEach((item) => {
|
|
116469
|
+
const reasons = keywordDisapprovalReasons(item);
|
|
116470
|
+
if (reasons.length === 0) return;
|
|
116471
|
+
const text4 = String(item["text"] ?? item["keywordText"] ?? item["id"] ?? "");
|
|
116472
|
+
console.log(` \u62D2\u5BA1 ${text4}\uFF1A${reasons.join("\uFF1B")}`);
|
|
116473
|
+
});
|
|
116451
116474
|
}
|
|
116452
116475
|
console.log();
|
|
116453
116476
|
}
|
|
@@ -117761,46 +117784,46 @@ function validateRsaDisplayPath(prefix, ad, errors, lengthViolations) {
|
|
|
117761
117784
|
`${prefix} \u68C0\u6D4B\u5230\u5C0F\u5199 path2="${String(ad["path2"])}"\uFF0C\u540E\u7AEF\u5951\u7EA6\u5B57\u6BB5\u4E3A Path2\uFF08PascalCase\uFF09\uFF0C\u5F53\u524D\u63D0\u4EA4\u4E0D\u4F1A\u751F\u6548`
|
|
117762
117785
|
);
|
|
117763
117786
|
}
|
|
117764
|
-
for (const [
|
|
117787
|
+
for (const [field5, label2, example] of [
|
|
117765
117788
|
["Path1", "\u663E\u793A\u8DEF\u5F84\u7B2C 1 \u6BB5", '"Path1": "products"'],
|
|
117766
117789
|
["Path2", "\u663E\u793A\u8DEF\u5F84\u7B2C 2 \u6BB5", '"Path2": "steel"']
|
|
117767
117790
|
]) {
|
|
117768
|
-
const raw = ad[
|
|
117791
|
+
const raw = ad[field5];
|
|
117769
117792
|
if (raw === void 0) {
|
|
117770
117793
|
pushErr2(
|
|
117771
117794
|
errors,
|
|
117772
|
-
`${prefix}.${
|
|
117795
|
+
`${prefix}.${field5} \u5B57\u6BB5\u7F3A\u5931\uFF08RSA \u5FC5\u586B\uFF09\u3002${label2}\uFF0C\u5C55\u793A\u4E3A finalUrl \u57DF\u540D\u540E\u7684\u8DEF\u5F84\u6BB5\uFF08\u226415 \u5B57\u7B26\uFF0CCJK \u6309 2 \u8BA1\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
|
|
117773
117796
|
);
|
|
117774
117797
|
continue;
|
|
117775
117798
|
}
|
|
117776
117799
|
if (raw === null) {
|
|
117777
117800
|
pushErr2(
|
|
117778
117801
|
errors,
|
|
117779
|
-
`${prefix}.${
|
|
117802
|
+
`${prefix}.${field5} \u4E3A null\uFF08RSA \u5FC5\u586B\uFF0C\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u53EF\u586B ""\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
|
|
117780
117803
|
);
|
|
117781
117804
|
continue;
|
|
117782
117805
|
}
|
|
117783
117806
|
if (typeof raw !== "string") {
|
|
117784
|
-
pushErr2(errors, `${prefix}.${
|
|
117807
|
+
pushErr2(errors, `${prefix}.${field5} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
|
|
117785
117808
|
continue;
|
|
117786
117809
|
}
|
|
117787
117810
|
const len = calcGoogleCharLength(raw);
|
|
117788
117811
|
if (len > 15) {
|
|
117789
117812
|
pushLengthViolation(lengthViolations, {
|
|
117790
|
-
path: `${prefix}.${
|
|
117791
|
-
field,
|
|
117813
|
+
path: `${prefix}.${field5}`,
|
|
117814
|
+
field: field5,
|
|
117792
117815
|
kind: "rsa_path",
|
|
117793
117816
|
limit: 15,
|
|
117794
117817
|
actual: len,
|
|
117795
117818
|
countMode: "google",
|
|
117796
117819
|
text: raw
|
|
117797
117820
|
});
|
|
117798
|
-
pushErr2(errors, `${prefix}.${
|
|
117821
|
+
pushErr2(errors, `${prefix}.${field5} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
|
|
117799
117822
|
}
|
|
117800
117823
|
if (raw.length > 0 && !PATH_SEGMENT_REGEX.test(raw)) {
|
|
117801
117824
|
pushErr2(
|
|
117802
117825
|
errors,
|
|
117803
|
-
`${prefix}.${
|
|
117826
|
+
`${prefix}.${field5} \u542B\u975E\u6CD5\u5B57\u7B26\u6216\u683C\u5F0F\uFF08\u4EC5\u5141\u8BB8\u5C0F\u5199 a-z\u30010-9\u3001\u8FDE\u5B57\u7B26\uFF0C\u4E14\u4E0D\u80FD\u4EE5\u8FDE\u5B57\u7B26\u5F00\u5934/\u7ED3\u5C3E\uFF09\uFF1A"${raw}"`
|
|
117804
117827
|
);
|
|
117805
117828
|
}
|
|
117806
117829
|
}
|
|
@@ -117839,10 +117862,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
|
|
|
117839
117862
|
for (let i = 0; i < headlines.length; i++) {
|
|
117840
117863
|
const len = calcGoogleCharLength(headlines[i]);
|
|
117841
117864
|
if (len > 30) {
|
|
117842
|
-
const
|
|
117865
|
+
const field5 = headlineFields[i] ?? `headline[${i}]`;
|
|
117843
117866
|
pushLengthViolation(lengthViolations, {
|
|
117844
|
-
path: `${prefix}.${
|
|
117845
|
-
field,
|
|
117867
|
+
path: `${prefix}.${field5}`,
|
|
117868
|
+
field: field5,
|
|
117846
117869
|
kind: "rsa_headline",
|
|
117847
117870
|
limit: 30,
|
|
117848
117871
|
actual: len,
|
|
@@ -117874,10 +117897,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
|
|
|
117874
117897
|
for (let i = 0; i < descriptions.length; i++) {
|
|
117875
117898
|
const len = calcGoogleCharLength(descriptions[i]);
|
|
117876
117899
|
if (len > 90) {
|
|
117877
|
-
const
|
|
117900
|
+
const field5 = descriptionFields[i] ?? `description[${i}]`;
|
|
117878
117901
|
pushLengthViolation(lengthViolations, {
|
|
117879
|
-
path: `${prefix}.${
|
|
117880
|
-
field,
|
|
117902
|
+
path: `${prefix}.${field5}`,
|
|
117903
|
+
field: field5,
|
|
117881
117904
|
kind: "rsa_description",
|
|
117882
117905
|
limit: 90,
|
|
117883
117906
|
actual: len,
|
|
@@ -119599,6 +119622,1098 @@ async function runAdEdit(opts) {
|
|
|
119599
119622
|
`);
|
|
119600
119623
|
}
|
|
119601
119624
|
|
|
119625
|
+
// src/commands/ad/exclusions.ts
|
|
119626
|
+
init_auth();
|
|
119627
|
+
init_cli_json_snapshot();
|
|
119628
|
+
init_cli_table();
|
|
119629
|
+
init_shared();
|
|
119630
|
+
var EXCLUSION_TYPES = [
|
|
119631
|
+
"content-label",
|
|
119632
|
+
"placement",
|
|
119633
|
+
"youtube-channel",
|
|
119634
|
+
"youtube-video",
|
|
119635
|
+
"app",
|
|
119636
|
+
"app-category"
|
|
119637
|
+
];
|
|
119638
|
+
var RESERVED_PLACEMENT_SUFFIXES = [".invalid", ".example", ".test", ".localhost"];
|
|
119639
|
+
function normalizePlacementUrl(raw) {
|
|
119640
|
+
const trimmed = raw.trim();
|
|
119641
|
+
if (!trimmed || /\s/.test(trimmed) || trimmed.includes(",")) {
|
|
119642
|
+
throw new Error("\u7248\u4F4D\u9700\u8981\u4E00\u4E2A\u7F51\u5740\uFF0C\u4E0D\u80FD\u542B\u7A7A\u683C\u3002\u4F8B\u5982 http://www.domain.com");
|
|
119643
|
+
}
|
|
119644
|
+
const withScheme = /^https?:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
|
|
119645
|
+
let url;
|
|
119646
|
+
try {
|
|
119647
|
+
url = new URL(withScheme);
|
|
119648
|
+
} catch {
|
|
119649
|
+
throw new Error("\u7248\u4F4D\u7F51\u5740\u683C\u5F0F\u4E0D\u5BF9\u3002\u4F8B\u5982 http://www.domain.com\uFF0C\u8DEF\u5F84\u6700\u591A\u4E24\u7EA7\u3002");
|
|
119650
|
+
}
|
|
119651
|
+
if (url.username || url.password || url.search || url.hash || !url.hostname.includes(".")) {
|
|
119652
|
+
throw new Error("\u7248\u4F4D\u7F51\u5740\u4E0D\u8981\u5E26\u8D26\u53F7\u3001\u53C2\u6570\u6216\u951A\u70B9\u3002\u4F8B\u5982 http://www.domain.com");
|
|
119653
|
+
}
|
|
119654
|
+
const host = url.hostname.toLowerCase();
|
|
119655
|
+
if (RESERVED_PLACEMENT_SUFFIXES.some((suffix) => host.endsWith(suffix))) {
|
|
119656
|
+
throw new Error("Google \u4E0D\u63A5\u53D7 .invalid\u3001.example\u3001.test \u8FD9\u7C7B\u4FDD\u7559\u57DF\u540D\u3002\u8BF7\u7528\u771F\u5B9E\u7F51\u7AD9\uFF0C\u4F8B\u5982 http://www.domain.com\u3002");
|
|
119657
|
+
}
|
|
119658
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
119659
|
+
if (parts.length > 2) {
|
|
119660
|
+
throw new Error("\u7248\u4F4D\u7F51\u5740\u6700\u591A\u4E24\u7EA7\u8DEF\u5F84\uFF0C\u4F8B\u5982 http://www.domain.com/news/2024");
|
|
119661
|
+
}
|
|
119662
|
+
const path58 = parts.length > 0 ? `/${parts.join("/")}` : "";
|
|
119663
|
+
return `${url.protocol}//${host}${path58}`;
|
|
119664
|
+
}
|
|
119665
|
+
var GROUP_LABEL = {
|
|
119666
|
+
sensitive: "\u654F\u611F\u5185\u5BB9",
|
|
119667
|
+
types: "\u7C7B\u578B\u548C\u6807\u7B7E",
|
|
119668
|
+
themes: "\u5185\u5BB9\u4E3B\u9898"
|
|
119669
|
+
};
|
|
119670
|
+
function buildExclusionCreateBody(input) {
|
|
119671
|
+
const type = input.type.trim().toLowerCase();
|
|
119672
|
+
if (!EXCLUSION_TYPES.includes(type)) {
|
|
119673
|
+
throw new Error(
|
|
119674
|
+
"type \u987B\u4E3A content-label | placement | youtube-channel | youtube-video | app | app-category"
|
|
119675
|
+
);
|
|
119676
|
+
}
|
|
119677
|
+
const filled = [
|
|
119678
|
+
input.contentLabel,
|
|
119679
|
+
input.url,
|
|
119680
|
+
input.channelId,
|
|
119681
|
+
input.videoId,
|
|
119682
|
+
input.appId,
|
|
119683
|
+
input.appCategoryId
|
|
119684
|
+
].filter((value) => value != null && String(value).trim() !== "");
|
|
119685
|
+
if (filled.length !== 1) {
|
|
119686
|
+
throw new Error("\u4E00\u6B21\u53EA\u586B\u4E00\u79CD\u503C\uFF1A\u5185\u5BB9\u6807\u7B7E\u3001\u7F51\u5740\u3001\u9891\u9053\u3001\u89C6\u9891\u3001\u5E94\u7528\u6216\u5E94\u7528\u7C7B\u522B id");
|
|
119687
|
+
}
|
|
119688
|
+
if (type === "content-label") {
|
|
119689
|
+
const contentLabel = input.contentLabel?.trim() ?? "";
|
|
119690
|
+
if (!contentLabel) throw new Error("content-label \u9700\u8981 --content-label");
|
|
119691
|
+
return { type, contentLabel };
|
|
119692
|
+
}
|
|
119693
|
+
if (type === "placement") {
|
|
119694
|
+
return { type, url: normalizePlacementUrl(input.url ?? "") };
|
|
119695
|
+
}
|
|
119696
|
+
if (type === "youtube-channel") {
|
|
119697
|
+
const channelId = input.channelId?.trim() ?? "";
|
|
119698
|
+
if (!channelId) throw new Error("youtube-channel \u9700\u8981 --channel-id");
|
|
119699
|
+
return { type, channelId };
|
|
119700
|
+
}
|
|
119701
|
+
if (type === "youtube-video") {
|
|
119702
|
+
const videoId = input.videoId?.trim() ?? "";
|
|
119703
|
+
if (!videoId) throw new Error("youtube-video \u9700\u8981 --video-id");
|
|
119704
|
+
return { type, videoId };
|
|
119705
|
+
}
|
|
119706
|
+
if (type === "app") {
|
|
119707
|
+
const appId = input.appId?.trim() ?? "";
|
|
119708
|
+
if (!/^[12]-.+/.test(appId)) {
|
|
119709
|
+
throw new Error("app \u7684 --app-id \u5F62\u5982 1-123456789\uFF08Apple\uFF09\u6216 2-com.example.app\uFF08Google Play\uFF09");
|
|
119710
|
+
}
|
|
119711
|
+
return { type, appId };
|
|
119712
|
+
}
|
|
119713
|
+
const appCategoryId = input.appCategoryId?.trim() ?? "";
|
|
119714
|
+
if (!/^\d+$/.test(appCategoryId)) {
|
|
119715
|
+
throw new Error("app-category \u9700\u8981 app-categories \u8FD4\u56DE\u7684\u6570\u5B57 --app-category-id");
|
|
119716
|
+
}
|
|
119717
|
+
return { type, appCategoryId };
|
|
119718
|
+
}
|
|
119719
|
+
function exclusionsUrl(googleApiUrl, accountId) {
|
|
119720
|
+
return `${googleApiUrl}/campaignmanagement/accounts/${accountId}/exclusions`;
|
|
119721
|
+
}
|
|
119722
|
+
function unwrapItems(body) {
|
|
119723
|
+
if (Array.isArray(body)) return body;
|
|
119724
|
+
if (body && typeof body === "object") {
|
|
119725
|
+
const record2 = body;
|
|
119726
|
+
const data = record2["data"] ?? record2["Data"] ?? record2["items"] ?? record2["Items"];
|
|
119727
|
+
if (Array.isArray(data)) return data;
|
|
119728
|
+
}
|
|
119729
|
+
return [];
|
|
119730
|
+
}
|
|
119731
|
+
function field(item, ...keys) {
|
|
119732
|
+
for (const key of keys) {
|
|
119733
|
+
const value = item[key];
|
|
119734
|
+
if (value != null && String(value).trim() !== "") return String(value);
|
|
119735
|
+
}
|
|
119736
|
+
return "";
|
|
119737
|
+
}
|
|
119738
|
+
async function runAdExclusionsList(opts) {
|
|
119739
|
+
opts = withResolvedAdAccount(opts);
|
|
119740
|
+
const config = loadConfig(opts.token);
|
|
119741
|
+
const url = exclusionsUrl(requireGoogleApi(config), opts.account);
|
|
119742
|
+
let items3;
|
|
119743
|
+
try {
|
|
119744
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
119745
|
+
} catch (err) {
|
|
119746
|
+
console.error(`
|
|
119747
|
+
\u274C \u67E5\u8BE2\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119748
|
+
`);
|
|
119749
|
+
process.exit(1);
|
|
119750
|
+
}
|
|
119751
|
+
if (opts.type) {
|
|
119752
|
+
const type = opts.type.trim().toLowerCase();
|
|
119753
|
+
items3 = items3.filter((item) => field(item, "type", "Type") === type);
|
|
119754
|
+
}
|
|
119755
|
+
const payload = { account: opts.account, count: items3.length, items: items3 };
|
|
119756
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
119757
|
+
section: "ad-exclusions",
|
|
119758
|
+
commandLabel: "ad exclusions list",
|
|
119759
|
+
payload
|
|
119760
|
+
})) {
|
|
119761
|
+
return;
|
|
119762
|
+
}
|
|
119763
|
+
console.log(`
|
|
119764
|
+
\u8D26\u6237\u7EA7\u5185\u5BB9\u6392\u9664\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF09`);
|
|
119765
|
+
console.log("\u8FD9\u662F\u5185\u5BB9\u9002\u5B9C\u6027\uFF0C\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\uFF0C\u4E5F\u4E0D\u662F\u5185\u5BB9\u5173\u952E\u5B57\u3002\n");
|
|
119766
|
+
if (items3.length === 0) {
|
|
119767
|
+
console.log(" \u6682\u65E0\u6392\u9664\u3002\n");
|
|
119768
|
+
return;
|
|
119769
|
+
}
|
|
119770
|
+
printCliTable(
|
|
119771
|
+
items3.map((item) => ({
|
|
119772
|
+
id: field(item, "criterionId", "CriterionId"),
|
|
119773
|
+
type: field(item, "type", "Type"),
|
|
119774
|
+
group: GROUP_LABEL[field(item, "group", "Group")] ?? field(item, "group", "Group"),
|
|
119775
|
+
value: field(item, "value", "Value", "labelZh", "LabelZh")
|
|
119776
|
+
})),
|
|
119777
|
+
[
|
|
119778
|
+
{ key: "id", header: "criterionId" },
|
|
119779
|
+
{ key: "type", header: "\u7C7B\u578B" },
|
|
119780
|
+
{ key: "group", header: "\u5206\u7EC4" },
|
|
119781
|
+
{ key: "value", header: "\u5185\u5BB9" }
|
|
119782
|
+
]
|
|
119783
|
+
);
|
|
119784
|
+
console.log();
|
|
119785
|
+
}
|
|
119786
|
+
async function runAdExclusionsAdd(opts) {
|
|
119787
|
+
opts = withResolvedAdAccount(opts);
|
|
119788
|
+
let body;
|
|
119789
|
+
try {
|
|
119790
|
+
body = buildExclusionCreateBody(opts);
|
|
119791
|
+
} catch (err) {
|
|
119792
|
+
console.error(`
|
|
119793
|
+
\u274C ${err instanceof Error ? err.message : String(err)}
|
|
119794
|
+
`);
|
|
119795
|
+
process.exit(1);
|
|
119796
|
+
}
|
|
119797
|
+
const config = loadConfig(opts.token);
|
|
119798
|
+
const url = exclusionsUrl(requireGoogleApi(config), opts.account);
|
|
119799
|
+
let created;
|
|
119800
|
+
try {
|
|
119801
|
+
created = await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
119802
|
+
} catch (err) {
|
|
119803
|
+
console.error(`
|
|
119804
|
+
\u274C \u6DFB\u52A0\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119805
|
+
`);
|
|
119806
|
+
process.exit(1);
|
|
119807
|
+
}
|
|
119808
|
+
const payload = { account: opts.account, request: body, response: created };
|
|
119809
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
119810
|
+
section: "ad-exclusions-add",
|
|
119811
|
+
commandLabel: "ad exclusions add",
|
|
119812
|
+
payload
|
|
119813
|
+
})) {
|
|
119814
|
+
return;
|
|
119815
|
+
}
|
|
119816
|
+
const item = created && typeof created === "object" ? created : {};
|
|
119817
|
+
console.log(
|
|
119818
|
+
`
|
|
119819
|
+
\u2705 \u5DF2\u6DFB\u52A0\u8D26\u6237\u7EA7\u6392\u9664 ${field(item, "type", "Type") || body.type} ${field(item, "value", "Value") || field(item, "criterionId", "CriterionId")}
|
|
119820
|
+
`
|
|
119821
|
+
);
|
|
119822
|
+
}
|
|
119823
|
+
async function runAdExclusionsRemove(opts) {
|
|
119824
|
+
opts = withResolvedAdAccount(opts);
|
|
119825
|
+
if (!/^\d+$/.test(opts.criterionId.trim())) {
|
|
119826
|
+
console.error("\n\u274C --criterion-id \u987B\u4E3A list \u8FD4\u56DE\u7684\u6570\u5B57\n");
|
|
119827
|
+
process.exit(1);
|
|
119828
|
+
}
|
|
119829
|
+
const config = loadConfig(opts.token);
|
|
119830
|
+
const url = `${exclusionsUrl(requireGoogleApi(config), opts.account)}/${opts.criterionId.trim()}`;
|
|
119831
|
+
try {
|
|
119832
|
+
await apiDeleteRaw(url, config, { verbose: opts.verbose });
|
|
119833
|
+
} catch (err) {
|
|
119834
|
+
console.error(`
|
|
119835
|
+
\u274C \u5220\u9664\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119836
|
+
`);
|
|
119837
|
+
process.exit(1);
|
|
119838
|
+
}
|
|
119839
|
+
console.log(`
|
|
119840
|
+
\u2705 \u5DF2\u5220\u9664\u5185\u5BB9\u6392\u9664 ${opts.criterionId}
|
|
119841
|
+
`);
|
|
119842
|
+
}
|
|
119843
|
+
async function runAdExclusionContentLabels(opts) {
|
|
119844
|
+
const config = loadConfig(opts.token);
|
|
119845
|
+
const url = `${requireGoogleApi(config)}/campaignmanagement/exclusions/content-labels`;
|
|
119846
|
+
let items3;
|
|
119847
|
+
try {
|
|
119848
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
119849
|
+
} catch (err) {
|
|
119850
|
+
console.error(`
|
|
119851
|
+
\u274C \u67E5\u8BE2\u5185\u5BB9\u6807\u7B7E\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119852
|
+
`);
|
|
119853
|
+
process.exit(1);
|
|
119854
|
+
}
|
|
119855
|
+
const payload = { count: items3.length, items: items3 };
|
|
119856
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
119857
|
+
section: "ad-exclusion-content-labels",
|
|
119858
|
+
commandLabel: "ad exclusions content-labels",
|
|
119859
|
+
payload
|
|
119860
|
+
})) {
|
|
119861
|
+
return;
|
|
119862
|
+
}
|
|
119863
|
+
console.log("\n\u5185\u5BB9\u6807\u7B7E\u3002\u5185\u5BB9\u4E3B\u9898\u4E5F\u662F content_label\uFF0C\u4E0D\u662F Topic\u3002\u5185\u5BB9\u5173\u952E\u5B57\u6CA1\u6709\u516C\u5F00\u5B57\u6BB5\u3002\n");
|
|
119864
|
+
printCliTable(
|
|
119865
|
+
items3.map((item) => ({
|
|
119866
|
+
group: GROUP_LABEL[field(item, "group", "Group")] ?? field(item, "group", "Group"),
|
|
119867
|
+
label: field(item, "labelZh", "LabelZh"),
|
|
119868
|
+
name: field(item, "contentLabel", "ContentLabel")
|
|
119869
|
+
})),
|
|
119870
|
+
[
|
|
119871
|
+
{ key: "group", header: "\u5206\u7EC4" },
|
|
119872
|
+
{ key: "label", header: "\u540D\u79F0" },
|
|
119873
|
+
{ key: "name", header: "contentLabel" }
|
|
119874
|
+
]
|
|
119875
|
+
);
|
|
119876
|
+
console.log();
|
|
119877
|
+
}
|
|
119878
|
+
async function runAdExclusionAppCategories(opts) {
|
|
119879
|
+
opts = withResolvedAdAccount(opts);
|
|
119880
|
+
const config = loadConfig(opts.token);
|
|
119881
|
+
const url = `${exclusionsUrl(requireGoogleApi(config), opts.account)}/app-categories`;
|
|
119882
|
+
let items3;
|
|
119883
|
+
try {
|
|
119884
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
119885
|
+
} catch (err) {
|
|
119886
|
+
console.error(`
|
|
119887
|
+
\u274C \u67E5\u8BE2\u5E94\u7528\u7C7B\u522B\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119888
|
+
`);
|
|
119889
|
+
process.exit(1);
|
|
119890
|
+
}
|
|
119891
|
+
const payload = { account: opts.account, count: items3.length, items: items3 };
|
|
119892
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
119893
|
+
section: "ad-exclusion-app-categories",
|
|
119894
|
+
commandLabel: "ad exclusions app-categories",
|
|
119895
|
+
payload
|
|
119896
|
+
})) {
|
|
119897
|
+
return;
|
|
119898
|
+
}
|
|
119899
|
+
console.log(`
|
|
119900
|
+
\u5E94\u7528\u7C7B\u522B\uFF08${items3.length} \u4E2A\uFF0C\u4EE5\u672C\u6B21\u67E5\u8BE2\u4E3A\u51C6\uFF09
|
|
119901
|
+
`);
|
|
119902
|
+
printCliTable(
|
|
119903
|
+
items3.map((item) => ({
|
|
119904
|
+
id: field(item, "id", "Id"),
|
|
119905
|
+
name: field(item, "name", "Name")
|
|
119906
|
+
})),
|
|
119907
|
+
[
|
|
119908
|
+
{ key: "id", header: "id" },
|
|
119909
|
+
{ key: "name", header: "\u540D\u79F0" }
|
|
119910
|
+
]
|
|
119911
|
+
);
|
|
119912
|
+
console.log();
|
|
119913
|
+
}
|
|
119914
|
+
|
|
119915
|
+
// src/commands/ad/account-insights.ts
|
|
119916
|
+
init_auth();
|
|
119917
|
+
init_cli_json_snapshot();
|
|
119918
|
+
init_cli_table();
|
|
119919
|
+
init_shared();
|
|
119920
|
+
function inclusiveDayCount(start, end) {
|
|
119921
|
+
const a = Date.parse(`${start}T00:00:00Z`);
|
|
119922
|
+
const b = Date.parse(`${end}T00:00:00Z`);
|
|
119923
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) {
|
|
119924
|
+
throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
|
|
119925
|
+
}
|
|
119926
|
+
return Math.round((b - a) / 864e5) + 1;
|
|
119927
|
+
}
|
|
119928
|
+
function isoDate(dateStr, offsetDays) {
|
|
119929
|
+
if (dateStr) {
|
|
119930
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
|
|
119931
|
+
return dateStr;
|
|
119932
|
+
}
|
|
119933
|
+
const d = /* @__PURE__ */ new Date();
|
|
119934
|
+
d.setDate(d.getDate() + offsetDays);
|
|
119935
|
+
return d.toISOString().slice(0, 10);
|
|
119936
|
+
}
|
|
119937
|
+
function assertChangeRange(start, end) {
|
|
119938
|
+
const days = inclusiveDayCount(start, end);
|
|
119939
|
+
if (days < 1) throw new Error("\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F");
|
|
119940
|
+
if (days > 30) throw new Error("\u64CD\u4F5C\u8BB0\u5F55\u53EA\u4FDD\u7559\u7EA6 30 \u5929\uFF0C\u8BF7\u628A\u533A\u95F4\u7F29\u5230 30 \u5929\u5185");
|
|
119941
|
+
}
|
|
119942
|
+
function field2(item, ...keys) {
|
|
119943
|
+
for (const key of keys) {
|
|
119944
|
+
const value = item[key];
|
|
119945
|
+
if (value != null && String(value).trim() !== "") return String(value);
|
|
119946
|
+
}
|
|
119947
|
+
return "";
|
|
119948
|
+
}
|
|
119949
|
+
function money(item) {
|
|
119950
|
+
const raw = item["spend"] ?? item["Spend"];
|
|
119951
|
+
const n = typeof raw === "number" ? raw : Number(raw);
|
|
119952
|
+
return Number.isFinite(n) ? n.toFixed(2) : "\u2014";
|
|
119953
|
+
}
|
|
119954
|
+
async function runAdPlacements(opts) {
|
|
119955
|
+
opts = withResolvedAdAccount(opts);
|
|
119956
|
+
let start;
|
|
119957
|
+
let end;
|
|
119958
|
+
try {
|
|
119959
|
+
start = isoDate(opts.start, -30);
|
|
119960
|
+
end = isoDate(opts.end, 0);
|
|
119961
|
+
} catch (err) {
|
|
119962
|
+
console.error(`
|
|
119963
|
+
\u274C ${err instanceof Error ? err.message : String(err)}
|
|
119964
|
+
`);
|
|
119965
|
+
process.exit(1);
|
|
119966
|
+
}
|
|
119967
|
+
const config = loadConfig(opts.token);
|
|
119968
|
+
const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/placements?startDate=${start}&endDate=${end}`;
|
|
119969
|
+
let items3;
|
|
119970
|
+
try {
|
|
119971
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
119972
|
+
} catch (err) {
|
|
119973
|
+
console.error(`
|
|
119974
|
+
\u274C \u67E5\u8BE2\u7248\u4F4D\u82B1\u8D39\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
119975
|
+
`);
|
|
119976
|
+
process.exit(1);
|
|
119977
|
+
}
|
|
119978
|
+
const payload = { account: opts.account, start, end, count: items3.length, items: items3 };
|
|
119979
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
119980
|
+
section: "ad-placements",
|
|
119981
|
+
commandLabel: "ad placements",
|
|
119982
|
+
payload
|
|
119983
|
+
})) {
|
|
119984
|
+
return;
|
|
119985
|
+
}
|
|
119986
|
+
console.log(`
|
|
119987
|
+
\u7248\u4F4D\u82B1\u8D39 ${start} ~ ${end}\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF0C\u6309\u82B1\u8D39\u964D\u5E8F\uFF0C\u6700\u591A 500\uFF09`);
|
|
119988
|
+
console.log("\u8FD9\u662F\u5177\u4F53\u7F51\u7AD9 / \u5E94\u7528 / \u9891\u9053\u3002Demand Gen \u6E20\u9053\u7ED3\u6784\u4ECD\u7528 ad demand-gen report\u3002\n");
|
|
119989
|
+
if (items3.length === 0) {
|
|
119990
|
+
console.log(" \u8FD9\u4E2A\u533A\u95F4\u6CA1\u6709\u5C55\u793A\u3002\n");
|
|
119991
|
+
return;
|
|
119992
|
+
}
|
|
119993
|
+
printCliTable(
|
|
119994
|
+
items3.map((item) => ({
|
|
119995
|
+
campaign: field2(item, "campaignName", "CampaignName"),
|
|
119996
|
+
type: field2(item, "placementType", "PlacementType"),
|
|
119997
|
+
name: field2(item, "displayName", "DisplayName") || field2(item, "placement", "Placement"),
|
|
119998
|
+
spend: money(item),
|
|
119999
|
+
clicks: field2(item, "clicks", "Clicks") || "0",
|
|
120000
|
+
conversions: field2(item, "conversions", "Conversions") || "0"
|
|
120001
|
+
})),
|
|
120002
|
+
[
|
|
120003
|
+
{ key: "campaign", header: "\u7CFB\u5217" },
|
|
120004
|
+
{ key: "type", header: "\u7C7B\u578B" },
|
|
120005
|
+
{ key: "name", header: "\u7248\u4F4D" },
|
|
120006
|
+
{ key: "spend", header: "\u82B1\u8D39" },
|
|
120007
|
+
{ key: "clicks", header: "\u70B9\u51FB" },
|
|
120008
|
+
{ key: "conversions", header: "\u8F6C\u5316" }
|
|
120009
|
+
]
|
|
120010
|
+
);
|
|
120011
|
+
console.log();
|
|
120012
|
+
}
|
|
120013
|
+
async function runAdConversionGoals(opts) {
|
|
120014
|
+
opts = withResolvedAdAccount(opts);
|
|
120015
|
+
if (opts.campaignId && !/^\d+$/.test(opts.campaignId.trim())) {
|
|
120016
|
+
console.error("\n\u274C --campaign-id \u987B\u4E3A\u6570\u5B57\n");
|
|
120017
|
+
process.exit(1);
|
|
120018
|
+
}
|
|
120019
|
+
const config = loadConfig(opts.token);
|
|
120020
|
+
const query = opts.campaignId ? `?campaignId=${opts.campaignId.trim()}` : "";
|
|
120021
|
+
const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/conversion-goals${query}`;
|
|
120022
|
+
let items3;
|
|
120023
|
+
try {
|
|
120024
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
120025
|
+
} catch (err) {
|
|
120026
|
+
console.error(`
|
|
120027
|
+
\u274C \u67E5\u8BE2\u8F6C\u5316\u76EE\u6807\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
120028
|
+
`);
|
|
120029
|
+
process.exit(1);
|
|
120030
|
+
}
|
|
120031
|
+
const payload = { account: opts.account, count: items3.length, items: items3 };
|
|
120032
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
120033
|
+
section: "ad-conversion-goals",
|
|
120034
|
+
commandLabel: "ad conversion-goals",
|
|
120035
|
+
payload
|
|
120036
|
+
})) {
|
|
120037
|
+
return;
|
|
120038
|
+
}
|
|
120039
|
+
console.log(`
|
|
120040
|
+
\u7CFB\u5217\u8BA1\u5165\u51FA\u4EF7\u7684\u8F6C\u5316\u76EE\u6807\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF09`);
|
|
120041
|
+
console.log("\u8FD9\u4E0D\u662F\u8D26\u6237\u91CC\u914D\u8FC7\u7684\u5168\u90E8\u8F6C\u5316\u52A8\u4F5C\u3002CPA \u5F02\u5E38\u65F6\u5148\u770B biddable\uFF0C\u4E0D\u8981\u5148\u6539\u51FA\u4EF7\u3002\n");
|
|
120042
|
+
printCliTable(
|
|
120043
|
+
items3.map((item) => ({
|
|
120044
|
+
campaign: field2(item, "campaignName", "CampaignName"),
|
|
120045
|
+
category: field2(item, "category", "Category"),
|
|
120046
|
+
origin: field2(item, "origin", "Origin"),
|
|
120047
|
+
biddable: String(item["biddable"] ?? item["Biddable"] ?? "")
|
|
120048
|
+
})),
|
|
120049
|
+
[
|
|
120050
|
+
{ key: "campaign", header: "\u7CFB\u5217" },
|
|
120051
|
+
{ key: "category", header: "\u7C7B\u522B" },
|
|
120052
|
+
{ key: "origin", header: "\u6765\u6E90" },
|
|
120053
|
+
{ key: "biddable", header: "\u8BA1\u5165\u51FA\u4EF7" }
|
|
120054
|
+
]
|
|
120055
|
+
);
|
|
120056
|
+
console.log();
|
|
120057
|
+
}
|
|
120058
|
+
async function runAdChanges(opts) {
|
|
120059
|
+
opts = withResolvedAdAccount(opts);
|
|
120060
|
+
try {
|
|
120061
|
+
assertChangeRange(opts.start, opts.end);
|
|
120062
|
+
} catch (err) {
|
|
120063
|
+
console.error(`
|
|
120064
|
+
\u274C ${err instanceof Error ? err.message : String(err)}
|
|
120065
|
+
`);
|
|
120066
|
+
process.exit(1);
|
|
120067
|
+
}
|
|
120068
|
+
const config = loadConfig(opts.token);
|
|
120069
|
+
const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/changes?startDate=${opts.start}&endDate=${opts.end}`;
|
|
120070
|
+
let items3;
|
|
120071
|
+
try {
|
|
120072
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
120073
|
+
} catch (err) {
|
|
120074
|
+
console.error(`
|
|
120075
|
+
\u274C \u67E5\u8BE2\u64CD\u4F5C\u8BB0\u5F55\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
120076
|
+
`);
|
|
120077
|
+
process.exit(1);
|
|
120078
|
+
}
|
|
120079
|
+
const payload = {
|
|
120080
|
+
account: opts.account,
|
|
120081
|
+
start: opts.start,
|
|
120082
|
+
end: opts.end,
|
|
120083
|
+
count: items3.length,
|
|
120084
|
+
note: "\u5B98\u65B9 change_event \u5927\u7EA6\u53EA\u4FDD\u7559 30 \u5929\u3002\u7A7A\u5217\u8868\u8868\u793A\u8FD9\u6BB5\u6CA1\u6709\u8BB0\u5F55\uFF0C\u4E0D\u662F\u67E5\u8BE2\u5931\u8D25\u3002",
|
|
120085
|
+
items: items3
|
|
120086
|
+
};
|
|
120087
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
120088
|
+
section: "ad-changes",
|
|
120089
|
+
commandLabel: "ad changes",
|
|
120090
|
+
payload
|
|
120091
|
+
})) {
|
|
120092
|
+
return;
|
|
120093
|
+
}
|
|
120094
|
+
console.log(`
|
|
120095
|
+
\u64CD\u4F5C\u8BB0\u5F55 ${opts.start} ~ ${opts.end}\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF0C\u6700\u591A 500\uFF09`);
|
|
120096
|
+
console.log("\u8D85\u8FC7\u5B98\u65B9\u4FDD\u7559\u671F\u65F6\u8FD9\u91CC\u662F\u7A7A\u7684\uFF0C\u4E0D\u8981\u8865\u5199\u3002\n");
|
|
120097
|
+
if (items3.length === 0) {
|
|
120098
|
+
console.log(" \u8FD9\u6BB5\u6CA1\u6709\u64CD\u4F5C\u8BB0\u5F55\u3002\n");
|
|
120099
|
+
return;
|
|
120100
|
+
}
|
|
120101
|
+
printCliTable(
|
|
120102
|
+
items3.map((item) => ({
|
|
120103
|
+
time: field2(item, "changeDateTime", "ChangeDateTime"),
|
|
120104
|
+
type: field2(item, "resourceType", "ResourceType"),
|
|
120105
|
+
op: field2(item, "operation", "Operation"),
|
|
120106
|
+
who: field2(item, "userEmail", "UserEmail") || field2(item, "clientType", "ClientType"),
|
|
120107
|
+
fields: field2(item, "changedFields", "ChangedFields")
|
|
120108
|
+
})),
|
|
120109
|
+
[
|
|
120110
|
+
{ key: "time", header: "\u65F6\u95F4" },
|
|
120111
|
+
{ key: "type", header: "\u8D44\u6E90" },
|
|
120112
|
+
{ key: "op", header: "\u64CD\u4F5C" },
|
|
120113
|
+
{ key: "who", header: "\u6765\u6E90" },
|
|
120114
|
+
{ key: "fields", header: "\u5B57\u6BB5" }
|
|
120115
|
+
]
|
|
120116
|
+
);
|
|
120117
|
+
console.log();
|
|
120118
|
+
}
|
|
120119
|
+
|
|
120120
|
+
// src/commands/ad/negative-list.ts
|
|
120121
|
+
init_auth();
|
|
120122
|
+
init_shared();
|
|
120123
|
+
function negativeListAttachUrl(googleApiUrl, accountId) {
|
|
120124
|
+
return `${googleApiUrl}/negativekeywordmanagement/account-list/${accountId}/attach`;
|
|
120125
|
+
}
|
|
120126
|
+
async function runAdNegativeList(opts) {
|
|
120127
|
+
if (!opts.jsonOut) {
|
|
120128
|
+
console.log("\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD\u5217\u8868\u3002\u6BCF\u6237\u4E00\u4E2A\uFF0C\u4E0D\u7BA1 YouTube / \u5C55\u793A\u5185\u5BB9\u3002");
|
|
120129
|
+
}
|
|
120130
|
+
await runAdKeywords({
|
|
120131
|
+
token: opts.token,
|
|
120132
|
+
account: opts.account,
|
|
120133
|
+
negative: true,
|
|
120134
|
+
level: "Account",
|
|
120135
|
+
jsonOut: opts.jsonOut,
|
|
120136
|
+
verbose: opts.verbose
|
|
120137
|
+
});
|
|
120138
|
+
}
|
|
120139
|
+
async function runAdNegativeListAdd(opts) {
|
|
120140
|
+
await runAdNegativeKeywordCreate({
|
|
120141
|
+
token: opts.token,
|
|
120142
|
+
account: opts.account,
|
|
120143
|
+
level: "Account",
|
|
120144
|
+
keywords: opts.keywords,
|
|
120145
|
+
keywordsFile: opts.keywordsFile,
|
|
120146
|
+
matchType: opts.matchType,
|
|
120147
|
+
jsonOut: opts.jsonOut,
|
|
120148
|
+
verbose: opts.verbose
|
|
120149
|
+
});
|
|
120150
|
+
}
|
|
120151
|
+
async function runAdNegativeListRemove(opts) {
|
|
120152
|
+
await runAdNegativeKeywordDelete({
|
|
120153
|
+
token: opts.token,
|
|
120154
|
+
account: opts.account,
|
|
120155
|
+
id: opts.id,
|
|
120156
|
+
verbose: opts.verbose
|
|
120157
|
+
});
|
|
120158
|
+
}
|
|
120159
|
+
async function runAdNegativeListAttach(opts) {
|
|
120160
|
+
opts = withResolvedAdAccount(opts);
|
|
120161
|
+
const config = loadConfig(opts.token);
|
|
120162
|
+
const url = negativeListAttachUrl(requireGoogleApi(config), opts.account);
|
|
120163
|
+
let response;
|
|
120164
|
+
try {
|
|
120165
|
+
response = await apiFetch2(url, config, { method: "POST", body: "{}" }, opts.verbose);
|
|
120166
|
+
} catch (err) {
|
|
120167
|
+
console.error(`
|
|
120168
|
+
\u274C \u6302\u63A5\u5426\u8BCD\u5217\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
120169
|
+
`);
|
|
120170
|
+
process.exit(1);
|
|
120171
|
+
}
|
|
120172
|
+
const item = response && typeof response === "object" ? response : {};
|
|
120173
|
+
const already = item["alreadyAttached"] ?? item["AlreadyAttached"];
|
|
120174
|
+
const sharedSetId = item["sharedSetId"] ?? item["SharedSetId"] ?? "";
|
|
120175
|
+
console.log(
|
|
120176
|
+
`
|
|
120177
|
+
\u2705 \u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5 sharedSetId=${String(sharedSetId)}${already ? "\uFF08\u672C\u6765\u5C31\u6302\u7740\uFF09" : ""}
|
|
120178
|
+
`
|
|
120179
|
+
);
|
|
120180
|
+
}
|
|
120181
|
+
|
|
120182
|
+
// src/commands/ad/pmax-protection.ts
|
|
120183
|
+
init_auth();
|
|
120184
|
+
init_cli_json_snapshot();
|
|
120185
|
+
init_cli_table();
|
|
120186
|
+
init_shared();
|
|
120187
|
+
function requireDigits(raw, label2) {
|
|
120188
|
+
const value = (raw ?? "").trim();
|
|
120189
|
+
if (!/^\d+$/.test(value)) throw new Error(`${label2} \u987B\u4E3A\u6570\u5B57`);
|
|
120190
|
+
return value;
|
|
120191
|
+
}
|
|
120192
|
+
function requireCampaignId(campaignId, hint) {
|
|
120193
|
+
const value = (campaignId ?? "").trim();
|
|
120194
|
+
if (!/^\d+$/.test(value)) {
|
|
120195
|
+
throw new Error(`${hint} \u5FC5\u987B\u5E26\u6570\u5B57 --campaign-id\u3002\u8FD9\u4E0D\u662F ad search-terms`);
|
|
120196
|
+
}
|
|
120197
|
+
return value;
|
|
120198
|
+
}
|
|
120199
|
+
function assertBrandEntityId(raw) {
|
|
120200
|
+
const value = (raw ?? "").trim();
|
|
120201
|
+
const mid = /^\/[a-z]\/[A-Za-z0-9_]+$/.test(value);
|
|
120202
|
+
if (!/^\d+$/.test(value) && !mid) {
|
|
120203
|
+
throw new Error("\u54C1\u724C id \u5FC5\u987B\u6765\u81EA pmax-brands search\uFF0C\u4E0D\u80FD\u624B\u5199\u54C1\u724C\u540D");
|
|
120204
|
+
}
|
|
120205
|
+
return value;
|
|
120206
|
+
}
|
|
120207
|
+
function assertWebpageOperator(raw) {
|
|
120208
|
+
const value = (raw ?? "").trim().toUpperCase();
|
|
120209
|
+
if (value === "EQUALS" || value === "CONTAINS") return value;
|
|
120210
|
+
throw new Error("\u7F51\u5740\u6761\u4EF6\u53EA\u63A5\u53D7 EQUALS \u6216 CONTAINS");
|
|
120211
|
+
}
|
|
120212
|
+
function assertKeywordText(raw) {
|
|
120213
|
+
const value = (raw ?? "").trim();
|
|
120214
|
+
if (!value || value.includes(",") || value.length > 80) {
|
|
120215
|
+
throw new Error("\u4E00\u6B21\u52A0\u4E00\u4E2A\u8BCD\uFF0C\u4E0D\u80FD\u4E3A\u7A7A\u3001\u4E0D\u80FD\u542B\u9017\u53F7\u3001\u4E0D\u80FD\u8D85\u8FC7 80 \u4E2A\u5B57\u7B26");
|
|
120216
|
+
}
|
|
120217
|
+
return value;
|
|
120218
|
+
}
|
|
120219
|
+
function hyphenRange(start, end, label2) {
|
|
120220
|
+
const from = isoDate(start, -30);
|
|
120221
|
+
const to = isoDate(end, 0);
|
|
120222
|
+
const days = inclusiveDayCount(from, to);
|
|
120223
|
+
if (days < 1) throw new Error("\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F");
|
|
120224
|
+
if (days > 366) throw new Error(`${label2}\u533A\u95F4\u4E0D\u80FD\u8D85\u8FC7 366 \u5929`);
|
|
120225
|
+
return { start: from, end: to };
|
|
120226
|
+
}
|
|
120227
|
+
function pmaxSearchTermsUrl(base2, account, campaignId, start, end) {
|
|
120228
|
+
const id = requireCampaignId(campaignId, "pmax-search-terms");
|
|
120229
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(start) || !/^\d{4}-\d{2}-\d{2}$/.test(end)) {
|
|
120230
|
+
throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
|
|
120231
|
+
}
|
|
120232
|
+
return `${base2}/campaignmanagement/accounts/${account}/pmax-search-terms?campaignId=${id}&startDate=${start}&endDate=${end}`;
|
|
120233
|
+
}
|
|
120234
|
+
function field3(item, ...keys) {
|
|
120235
|
+
for (const key of keys) {
|
|
120236
|
+
const value = item[key];
|
|
120237
|
+
if (value != null && String(value).trim() !== "") return String(value);
|
|
120238
|
+
}
|
|
120239
|
+
return "";
|
|
120240
|
+
}
|
|
120241
|
+
function fail(err, label2) {
|
|
120242
|
+
console.error(`
|
|
120243
|
+
\u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
120244
|
+
`);
|
|
120245
|
+
process.exit(1);
|
|
120246
|
+
}
|
|
120247
|
+
function accountBase(opts) {
|
|
120248
|
+
const resolved = withResolvedAdAccount(opts);
|
|
120249
|
+
const config = loadConfig(resolved.token);
|
|
120250
|
+
return { config, base: requireGoogleApi(config), account: resolved.account };
|
|
120251
|
+
}
|
|
120252
|
+
async function runAdPmaxSearchTerms(opts) {
|
|
120253
|
+
let url;
|
|
120254
|
+
let range;
|
|
120255
|
+
try {
|
|
120256
|
+
range = hyphenRange(opts.start, opts.end, "PMax \u641C\u7D22\u8BCD");
|
|
120257
|
+
const { base: base2, account: account2 } = accountBase(opts);
|
|
120258
|
+
url = pmaxSearchTermsUrl(base2, account2, opts.campaignId ?? "", range.start, range.end);
|
|
120259
|
+
} catch (err) {
|
|
120260
|
+
fail(err, "\u53C2\u6570");
|
|
120261
|
+
}
|
|
120262
|
+
const { config, account } = accountBase(opts);
|
|
120263
|
+
let items3;
|
|
120264
|
+
try {
|
|
120265
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
120266
|
+
} catch (err) {
|
|
120267
|
+
fail(err, "\u67E5\u8BE2 PMax \u641C\u7D22\u8BCD\u5931\u8D25");
|
|
120268
|
+
}
|
|
120269
|
+
const payload = { account, campaignId: opts.campaignId, ...range, count: items3.length, items: items3 };
|
|
120270
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-search-terms", commandLabel: "ad pmax-search-terms", payload })) return;
|
|
120271
|
+
console.log(`
|
|
120272
|
+
PMax \u641C\u7D22\u8BCD ${range.start} ~ ${range.end}\uFF08\u7CFB\u5217 ${opts.campaignId}\uFF0C${items3.length} \u6761\uFF09`);
|
|
120273
|
+
console.log("\u8FD9\u662F PMax \u7684\u641C\u7D22\u67E5\u8BE2\u3002\u8FD9\u5F20\u8868\u6CA1\u6709\u82B1\u8D39\uFF0C\u6309\u5C55\u793A\u770B\u70ED\u5EA6\u3002\u641C\u7D22\u5E7F\u544A\u4ECD\u7528 ad search-terms\u3002\n");
|
|
120274
|
+
printCliTable(
|
|
120275
|
+
items3.map((item) => ({
|
|
120276
|
+
term: field3(item, "searchTerm", "SearchTerm"),
|
|
120277
|
+
category: field3(item, "categoryLabel", "CategoryLabel"),
|
|
120278
|
+
impressions: field3(item, "impressions", "Impressions") || "0",
|
|
120279
|
+
clicks: field3(item, "clicks", "Clicks") || "0"
|
|
120280
|
+
})),
|
|
120281
|
+
[
|
|
120282
|
+
{ key: "term", header: "\u641C\u7D22\u8BCD" },
|
|
120283
|
+
{ key: "category", header: "\u7C7B\u522B" },
|
|
120284
|
+
{ key: "impressions", header: "\u5C55\u793A" },
|
|
120285
|
+
{ key: "clicks", header: "\u70B9\u51FB" }
|
|
120286
|
+
]
|
|
120287
|
+
);
|
|
120288
|
+
console.log();
|
|
120289
|
+
}
|
|
120290
|
+
async function runAdPmaxBrandsSearch(opts) {
|
|
120291
|
+
const prefix = (opts.prefix ?? "").trim();
|
|
120292
|
+
if (!prefix) fail(new Error("prefix \u4E0D\u80FD\u4E3A\u7A7A"), "\u53C2\u6570");
|
|
120293
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120294
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/suggestions?prefix=${encodeURIComponent(prefix)}`;
|
|
120295
|
+
let items3;
|
|
120296
|
+
try {
|
|
120297
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
120298
|
+
} catch (err) {
|
|
120299
|
+
fail(err, "\u67E5\u8BE2\u54C1\u724C\u5EFA\u8BAE\u5931\u8D25");
|
|
120300
|
+
}
|
|
120301
|
+
const payload = { account, prefix, count: items3.length, items: items3 };
|
|
120302
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-brands-search", commandLabel: "ad pmax-brands search", payload })) return;
|
|
120303
|
+
console.log(`
|
|
120304
|
+
\u54C1\u724C\u5EFA\u8BAE\u300C${prefix}\u300D\uFF08${items3.length} \u6761\uFF09\u3002add \u65F6\u7528 id\uFF0C\u4E0D\u8981\u7528 name\u3002
|
|
120305
|
+
`);
|
|
120306
|
+
printCliTable(
|
|
120307
|
+
items3.map((item) => ({
|
|
120308
|
+
id: field3(item, "id", "Id"),
|
|
120309
|
+
name: field3(item, "name", "Name")
|
|
120310
|
+
})),
|
|
120311
|
+
[
|
|
120312
|
+
{ key: "id", header: "id" },
|
|
120313
|
+
{ key: "name", header: "\u540D\u79F0" }
|
|
120314
|
+
]
|
|
120315
|
+
);
|
|
120316
|
+
console.log();
|
|
120317
|
+
}
|
|
120318
|
+
async function runAdPmaxBrandsList(opts) {
|
|
120319
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120320
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands`;
|
|
120321
|
+
let body;
|
|
120322
|
+
try {
|
|
120323
|
+
const raw = await apiFetch2(url, config, {}, opts.verbose);
|
|
120324
|
+
body = raw && typeof raw === "object" ? raw : {};
|
|
120325
|
+
} catch (err) {
|
|
120326
|
+
fail(err, "\u67E5\u8BE2\u54C1\u724C\u5217\u8868\u5931\u8D25");
|
|
120327
|
+
}
|
|
120328
|
+
const lists = unwrapItems(body["lists"] ?? body["Lists"] ?? []);
|
|
120329
|
+
const attachments = unwrapItems(body["attachments"] ?? body["Attachments"] ?? []);
|
|
120330
|
+
const payload = { account, lists, attachments };
|
|
120331
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-brands", commandLabel: "ad pmax-brands list", payload })) return;
|
|
120332
|
+
console.log(`
|
|
120333
|
+
\u54C1\u724C\u5217\u8868\u6210\u5458 ${lists.length} \u6761\uFF0C\u5DF2\u6302\u7CFB\u5217 ${attachments.length} \u6761
|
|
120334
|
+
`);
|
|
120335
|
+
if (lists.length > 0) {
|
|
120336
|
+
printCliTable(
|
|
120337
|
+
lists.map((item) => ({
|
|
120338
|
+
set: field3(item, "sharedSetName", "SharedSetName"),
|
|
120339
|
+
id: field3(item, "entityId", "EntityId"),
|
|
120340
|
+
name: field3(item, "displayName", "DisplayName")
|
|
120341
|
+
})),
|
|
120342
|
+
[
|
|
120343
|
+
{ key: "set", header: "\u5217\u8868" },
|
|
120344
|
+
{ key: "id", header: "\u54C1\u724C id" },
|
|
120345
|
+
{ key: "name", header: "\u540D\u79F0" }
|
|
120346
|
+
]
|
|
120347
|
+
);
|
|
120348
|
+
}
|
|
120349
|
+
console.log();
|
|
120350
|
+
}
|
|
120351
|
+
async function runAdPmaxBrandsAdd(opts) {
|
|
120352
|
+
let entityId;
|
|
120353
|
+
try {
|
|
120354
|
+
entityId = assertBrandEntityId(opts.entityId);
|
|
120355
|
+
} catch (err) {
|
|
120356
|
+
fail(err, "\u53C2\u6570");
|
|
120357
|
+
}
|
|
120358
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120359
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands`;
|
|
120360
|
+
try {
|
|
120361
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ entityId }) }, opts.verbose);
|
|
120362
|
+
} catch (err) {
|
|
120363
|
+
fail(err, "\u6DFB\u52A0\u54C1\u724C\u5931\u8D25");
|
|
120364
|
+
}
|
|
120365
|
+
console.log(`
|
|
120366
|
+
\u2705 \u5DF2\u628A\u54C1\u724C ${entityId} \u5199\u5165 PMax \u54C1\u724C\u5217\u8868
|
|
120367
|
+
`);
|
|
120368
|
+
}
|
|
120369
|
+
async function runAdPmaxBrandsAttach(opts) {
|
|
120370
|
+
let campaignId;
|
|
120371
|
+
try {
|
|
120372
|
+
campaignId = requireCampaignId(opts.campaignId, "pmax-brands attach");
|
|
120373
|
+
} catch (err) {
|
|
120374
|
+
fail(err, "\u53C2\u6570");
|
|
120375
|
+
}
|
|
120376
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120377
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/attach`;
|
|
120378
|
+
const body = { campaignId };
|
|
120379
|
+
if (opts.sharedSetId?.trim()) body.sharedSetId = opts.sharedSetId.trim();
|
|
120380
|
+
try {
|
|
120381
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
120382
|
+
} catch (err) {
|
|
120383
|
+
fail(err, "\u6302\u63A5\u54C1\u724C\u5217\u8868\u5931\u8D25");
|
|
120384
|
+
}
|
|
120385
|
+
console.log(`
|
|
120386
|
+
\u2705 \u5DF2\u628A\u54C1\u724C\u5217\u8868\u6302\u5230\u7CFB\u5217 ${campaignId}\u3002\u5378\u4E0B\u7528 detach\uFF0C\u4E0D\u4F1A\u5220\u9664\u5217\u8868\u91CC\u7684\u54C1\u724C\u3002
|
|
120387
|
+
`);
|
|
120388
|
+
}
|
|
120389
|
+
async function runAdPmaxBrandsDetach(opts) {
|
|
120390
|
+
let campaignId;
|
|
120391
|
+
let criterionId;
|
|
120392
|
+
try {
|
|
120393
|
+
campaignId = requireCampaignId(opts.campaignId, "pmax-brands detach");
|
|
120394
|
+
criterionId = requireDigits(opts.criterionId, "--criterion-id");
|
|
120395
|
+
} catch (err) {
|
|
120396
|
+
fail(err, "\u53C2\u6570");
|
|
120397
|
+
}
|
|
120398
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120399
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/detach`;
|
|
120400
|
+
try {
|
|
120401
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ campaignId, criterionId }) }, opts.verbose);
|
|
120402
|
+
} catch (err) {
|
|
120403
|
+
fail(err, "\u5378\u4E0B\u54C1\u724C\u5217\u8868\u5931\u8D25");
|
|
120404
|
+
}
|
|
120405
|
+
console.log(`
|
|
120406
|
+
\u2705 \u5DF2\u4ECE\u7CFB\u5217 ${campaignId} \u5378\u4E0B\u54C1\u724C\u5217\u8868 ${criterionId}
|
|
120407
|
+
`);
|
|
120408
|
+
}
|
|
120409
|
+
async function listCampaignRows(opts, path58, label2) {
|
|
120410
|
+
let campaignId;
|
|
120411
|
+
try {
|
|
120412
|
+
campaignId = requireCampaignId(opts.campaignId, label2);
|
|
120413
|
+
} catch (err) {
|
|
120414
|
+
fail(err, "\u53C2\u6570");
|
|
120415
|
+
}
|
|
120416
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120417
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/${path58}?campaignId=${campaignId}`;
|
|
120418
|
+
let items3;
|
|
120419
|
+
try {
|
|
120420
|
+
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
120421
|
+
} catch (err) {
|
|
120422
|
+
fail(err, `\u67E5\u8BE2${label2}\u5931\u8D25`);
|
|
120423
|
+
}
|
|
120424
|
+
return { account, campaignId, items: items3 };
|
|
120425
|
+
}
|
|
120426
|
+
async function runAdPmaxNegativesList(opts) {
|
|
120427
|
+
const listed = await listCampaignRows(opts, "pmax-negatives", "pmax-negatives");
|
|
120428
|
+
if (!listed) return;
|
|
120429
|
+
const payload = { ...listed, count: listed.items.length };
|
|
120430
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-negatives", commandLabel: "ad pmax-negatives list", payload })) return;
|
|
120431
|
+
console.log(`
|
|
120432
|
+
PMax \u7CFB\u5217\u5426\u8BCD\uFF08\u7CFB\u5217 ${listed.campaignId}\uFF0C${listed.items.length} \u6761\uFF09`);
|
|
120433
|
+
console.log("\u8FD9\u4E0D\u662F ad negative-list\u3002\u4E0A\u9650\u4EE5 Google \u8FD4\u56DE\u7684\u9519\u8BEF\u4E3A\u51C6\u3002\n");
|
|
120434
|
+
printCliTable(
|
|
120435
|
+
listed.items.map((item) => ({
|
|
120436
|
+
id: field3(item, "criterionId", "CriterionId"),
|
|
120437
|
+
text: field3(item, "text", "Text"),
|
|
120438
|
+
match: field3(item, "matchType", "MatchType")
|
|
120439
|
+
})),
|
|
120440
|
+
[
|
|
120441
|
+
{ key: "id", header: "id" },
|
|
120442
|
+
{ key: "text", header: "\u8BCD" },
|
|
120443
|
+
{ key: "match", header: "\u5339\u914D" }
|
|
120444
|
+
]
|
|
120445
|
+
);
|
|
120446
|
+
console.log();
|
|
120447
|
+
}
|
|
120448
|
+
async function runAdPmaxNegativesAdd(opts) {
|
|
120449
|
+
let campaignId;
|
|
120450
|
+
let text4;
|
|
120451
|
+
let matchType;
|
|
120452
|
+
try {
|
|
120453
|
+
campaignId = requireCampaignId(opts.campaignId, "pmax-negatives add");
|
|
120454
|
+
text4 = assertKeywordText(opts.text);
|
|
120455
|
+
matchType = opts.matchType?.trim() || "Broad";
|
|
120456
|
+
if (!/^(broad|phrase|exact)$/i.test(matchType)) throw new Error("matchType \u987B\u4E3A Broad\u3001Phrase \u6216 Exact");
|
|
120457
|
+
} catch (err) {
|
|
120458
|
+
fail(err, "\u53C2\u6570");
|
|
120459
|
+
}
|
|
120460
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120461
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-negatives`;
|
|
120462
|
+
try {
|
|
120463
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ campaignId, text: text4, matchType }) }, opts.verbose);
|
|
120464
|
+
} catch (err) {
|
|
120465
|
+
fail(err, "\u6DFB\u52A0 PMax \u5426\u8BCD\u5931\u8D25");
|
|
120466
|
+
}
|
|
120467
|
+
console.log(`
|
|
120468
|
+
\u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6DFB\u52A0\u5426\u8BCD ${text4}
|
|
120469
|
+
`);
|
|
120470
|
+
}
|
|
120471
|
+
async function runAdPmaxNegativesRemove(opts) {
|
|
120472
|
+
await removeCampaignCriterion(opts, "pmax-negatives", "PMax \u5426\u8BCD");
|
|
120473
|
+
}
|
|
120474
|
+
async function runAdPmaxUrlsList(opts) {
|
|
120475
|
+
const listed = await listCampaignRows(opts, "pmax-urls", "pmax-urls");
|
|
120476
|
+
if (!listed) return;
|
|
120477
|
+
const payload = { ...listed, count: listed.items.length };
|
|
120478
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-urls", commandLabel: "ad pmax-urls list", payload })) return;
|
|
120479
|
+
console.log(`
|
|
120480
|
+
PMax \u7F51\u5740\u6392\u9664\uFF08\u7CFB\u5217 ${listed.campaignId}\uFF0C${listed.items.length} \u6761\uFF09`);
|
|
120481
|
+
console.log("\u8FD9\u4E0D\u662F pmax-edit \u7684\u7F51\u5740\u6269\u5C55\u5F00\u5173\u3002\u6B63\u5411\u7F51\u5740\u89C4\u5219\u4ECD\u8981\u5728\u540E\u53F0\u8BBE\u7F6E\u3002\n");
|
|
120482
|
+
printCliTable(
|
|
120483
|
+
listed.items.map((item) => ({
|
|
120484
|
+
id: field3(item, "criterionId", "CriterionId"),
|
|
120485
|
+
op: field3(item, "operator", "Operator"),
|
|
120486
|
+
url: field3(item, "url", "Url")
|
|
120487
|
+
})),
|
|
120488
|
+
[
|
|
120489
|
+
{ key: "id", header: "id" },
|
|
120490
|
+
{ key: "op", header: "\u6761\u4EF6" },
|
|
120491
|
+
{ key: "url", header: "\u7F51\u5740" }
|
|
120492
|
+
]
|
|
120493
|
+
);
|
|
120494
|
+
console.log();
|
|
120495
|
+
}
|
|
120496
|
+
async function runAdPmaxUrlsAdd(opts) {
|
|
120497
|
+
let campaignId;
|
|
120498
|
+
let operator;
|
|
120499
|
+
const urlValue = (opts.url ?? "").trim();
|
|
120500
|
+
try {
|
|
120501
|
+
campaignId = requireCampaignId(opts.campaignId, "pmax-urls add");
|
|
120502
|
+
operator = assertWebpageOperator(opts.operator);
|
|
120503
|
+
if (!urlValue || urlValue.includes(" ")) throw new Error("\u7F51\u5740\u6392\u9664\u9700\u8981\u4E00\u4E2A URL\uFF0C\u4E0D\u80FD\u542B\u7A7A\u683C");
|
|
120504
|
+
} catch (err) {
|
|
120505
|
+
fail(err, "\u53C2\u6570");
|
|
120506
|
+
}
|
|
120507
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120508
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/pmax-urls`;
|
|
120509
|
+
try {
|
|
120510
|
+
await apiFetch2(
|
|
120511
|
+
url,
|
|
120512
|
+
config,
|
|
120513
|
+
{ method: "POST", body: JSON.stringify({ campaignId, url: urlValue, operator }) },
|
|
120514
|
+
opts.verbose
|
|
120515
|
+
);
|
|
120516
|
+
} catch (err) {
|
|
120517
|
+
fail(err, "\u6DFB\u52A0\u7F51\u5740\u6392\u9664\u5931\u8D25");
|
|
120518
|
+
}
|
|
120519
|
+
console.log(`
|
|
120520
|
+
\u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6392\u9664\u7F51\u5740 ${urlValue}
|
|
120521
|
+
`);
|
|
120522
|
+
}
|
|
120523
|
+
async function runAdPmaxUrlsRemove(opts) {
|
|
120524
|
+
await removeCampaignCriterion(opts, "pmax-urls", "\u7F51\u5740\u6392\u9664");
|
|
120525
|
+
}
|
|
120526
|
+
async function removeCampaignCriterion(opts, path58, label2) {
|
|
120527
|
+
let campaignId;
|
|
120528
|
+
let criterionId;
|
|
120529
|
+
try {
|
|
120530
|
+
campaignId = requireCampaignId(opts.campaignId, path58);
|
|
120531
|
+
criterionId = requireDigits(opts.criterionId, "--criterion-id");
|
|
120532
|
+
} catch (err) {
|
|
120533
|
+
fail(err, "\u53C2\u6570");
|
|
120534
|
+
}
|
|
120535
|
+
const { config, base: base2, account } = accountBase(opts);
|
|
120536
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/${path58}/${criterionId}?campaignId=${campaignId}`;
|
|
120537
|
+
try {
|
|
120538
|
+
await apiDeleteRaw(url, config, { verbose: opts.verbose });
|
|
120539
|
+
} catch (err) {
|
|
120540
|
+
fail(err, `\u5220\u9664${label2}\u5931\u8D25`);
|
|
120541
|
+
}
|
|
120542
|
+
console.log(`
|
|
120543
|
+
\u2705 \u5DF2\u5220\u9664${label2} ${criterionId}
|
|
120544
|
+
`);
|
|
120545
|
+
}
|
|
120546
|
+
|
|
120547
|
+
// src/commands/ad/account-diagnostics.ts
|
|
120548
|
+
init_auth();
|
|
120549
|
+
init_cli_json_snapshot();
|
|
120550
|
+
init_cli_table();
|
|
120551
|
+
init_shared();
|
|
120552
|
+
function assertIpv4OrCidr(raw) {
|
|
120553
|
+
const value = (raw ?? "").trim();
|
|
120554
|
+
const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,2}))?$/.exec(value);
|
|
120555
|
+
if (!match) throw new Error("IP \u53EA\u63A5\u53D7\u5355\u4E2A IPv4\uFF0C\u6216 IPv4/\u524D\u7F00\u957F\u5EA6");
|
|
120556
|
+
const octets = [match[1], match[2], match[3], match[4]].map((part) => Number(part));
|
|
120557
|
+
if (octets.some((part) => part > 255)) throw new Error("IP \u53EA\u63A5\u53D7\u5355\u4E2A IPv4\uFF0C\u6216 IPv4/\u524D\u7F00\u957F\u5EA6");
|
|
120558
|
+
if (match[5] != null) {
|
|
120559
|
+
const prefix = Number(match[5]);
|
|
120560
|
+
if (prefix > 32) throw new Error("IPv4 \u524D\u7F00\u957F\u5EA6\u987B\u4E3A 0 \u5230 32");
|
|
120561
|
+
}
|
|
120562
|
+
return value;
|
|
120563
|
+
}
|
|
120564
|
+
function field4(item, ...keys) {
|
|
120565
|
+
for (const key of keys) {
|
|
120566
|
+
const value = item[key];
|
|
120567
|
+
if (value != null && String(value).trim() !== "") return String(value);
|
|
120568
|
+
}
|
|
120569
|
+
return "";
|
|
120570
|
+
}
|
|
120571
|
+
function fail2(err, label2) {
|
|
120572
|
+
console.error(`
|
|
120573
|
+
\u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
120574
|
+
`);
|
|
120575
|
+
process.exit(1);
|
|
120576
|
+
}
|
|
120577
|
+
function accountBase2(opts) {
|
|
120578
|
+
const resolved = withResolvedAdAccount(opts);
|
|
120579
|
+
const config = loadConfig(resolved.token);
|
|
120580
|
+
return { config, base: requireGoogleApi(config), account: resolved.account };
|
|
120581
|
+
}
|
|
120582
|
+
async function getItems(url, config, verbose) {
|
|
120583
|
+
return unwrapItems(await apiFetch2(url, config, {}, verbose));
|
|
120584
|
+
}
|
|
120585
|
+
async function runAdRsaAssets(opts) {
|
|
120586
|
+
let range;
|
|
120587
|
+
try {
|
|
120588
|
+
range = hyphenRange(opts.start, opts.end, "\u7D20\u6750\u62A5\u8868");
|
|
120589
|
+
} catch (err) {
|
|
120590
|
+
fail2(err, "\u53C2\u6570");
|
|
120591
|
+
}
|
|
120592
|
+
const { config, base: base2, account } = accountBase2(opts);
|
|
120593
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/rsa-assets?startDate=${range.start}&endDate=${range.end}`;
|
|
120594
|
+
let items3;
|
|
120595
|
+
try {
|
|
120596
|
+
items3 = await getItems(url, config, opts.verbose);
|
|
120597
|
+
} catch (err) {
|
|
120598
|
+
fail2(err, "\u67E5\u8BE2\u7D20\u6750\u8868\u73B0\u5931\u8D25");
|
|
120599
|
+
}
|
|
120600
|
+
const payload = { account, ...range, count: items3.length, items: items3 };
|
|
120601
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-rsa-assets", commandLabel: "ad rsa-assets", payload })) return;
|
|
120602
|
+
console.log(`
|
|
120603
|
+
\u641C\u7D22\u5E7F\u544A\u7D20\u6750 ${range.start} ~ ${range.end}\uFF08${items3.length} \u6761\uFF09
|
|
120604
|
+
`);
|
|
120605
|
+
printCliTable(
|
|
120606
|
+
items3.map((item) => ({
|
|
120607
|
+
fieldType: field4(item, "fieldType", "FieldType"),
|
|
120608
|
+
label: field4(item, "performanceLabel", "PerformanceLabel"),
|
|
120609
|
+
text: field4(item, "text", "Text"),
|
|
120610
|
+
spend: field4(item, "spend", "Spend")
|
|
120611
|
+
})),
|
|
120612
|
+
[
|
|
120613
|
+
{ key: "fieldType", header: "\u5B57\u6BB5" },
|
|
120614
|
+
{ key: "label", header: "\u8868\u73B0" },
|
|
120615
|
+
{ key: "text", header: "\u6587\u6848" },
|
|
120616
|
+
{ key: "spend", header: "\u82B1\u8D39" }
|
|
120617
|
+
]
|
|
120618
|
+
);
|
|
120619
|
+
console.log();
|
|
120620
|
+
}
|
|
120621
|
+
async function runAdRecommendationSubscriptions(opts) {
|
|
120622
|
+
const { config, base: base2, account } = accountBase2(opts);
|
|
120623
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/recommendation-subscriptions`;
|
|
120624
|
+
let items3;
|
|
120625
|
+
try {
|
|
120626
|
+
items3 = await getItems(url, config, opts.verbose);
|
|
120627
|
+
} catch (err) {
|
|
120628
|
+
fail2(err, "\u67E5\u8BE2\u5EFA\u8BAE\u8BA2\u9605\u5931\u8D25");
|
|
120629
|
+
}
|
|
120630
|
+
const payload = {
|
|
120631
|
+
account,
|
|
120632
|
+
count: items3.length,
|
|
120633
|
+
note: "\u53EA\u8BFB\u3002Enabled \u7684\u9AD8\u98CE\u9669\u9879\u8981\u5230 Google Ads \u540E\u53F0\u5173\u95ED\u3002\u672C\u547D\u4EE4\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3\u3002",
|
|
120634
|
+
items: items3
|
|
120635
|
+
};
|
|
120636
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
120637
|
+
section: "ad-recommendation-subscriptions",
|
|
120638
|
+
commandLabel: "ad recommendation-subscriptions",
|
|
120639
|
+
payload
|
|
120640
|
+
})) {
|
|
120641
|
+
return;
|
|
120642
|
+
}
|
|
120643
|
+
console.log(`
|
|
120644
|
+
\u81EA\u52A8\u5E94\u7528\u5EFA\u8BAE\u8BA2\u9605\uFF08${items3.length} \u6761\uFF09`);
|
|
120645
|
+
console.log("\u770B\u5230 Enabled \u65F6\u5230\u540E\u53F0\u5173\u95ED\u3002\u8FD9\u91CC\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3\u3002\n");
|
|
120646
|
+
printCliTable(
|
|
120647
|
+
items3.map((item) => ({
|
|
120648
|
+
type: field4(item, "type", "Type"),
|
|
120649
|
+
status: field4(item, "status", "Status")
|
|
120650
|
+
})),
|
|
120651
|
+
[
|
|
120652
|
+
{ key: "type", header: "\u7C7B\u578B" },
|
|
120653
|
+
{ key: "status", header: "\u72B6\u6001" }
|
|
120654
|
+
]
|
|
120655
|
+
);
|
|
120656
|
+
console.log();
|
|
120657
|
+
}
|
|
120658
|
+
async function runAdIpExclusionsList(opts) {
|
|
120659
|
+
const { config, base: base2, account } = accountBase2(opts);
|
|
120660
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions`;
|
|
120661
|
+
let items3;
|
|
120662
|
+
try {
|
|
120663
|
+
items3 = await getItems(url, config, opts.verbose);
|
|
120664
|
+
} catch (err) {
|
|
120665
|
+
fail2(err, "\u67E5\u8BE2 IP \u6392\u9664\u5931\u8D25");
|
|
120666
|
+
}
|
|
120667
|
+
const payload = { account, count: items3.length, items: items3 };
|
|
120668
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-ip-exclusions", commandLabel: "ad ip-exclusions list", payload })) return;
|
|
120669
|
+
console.log(`
|
|
120670
|
+
\u8D26\u6237\u7EA7 IP \u6392\u9664\uFF08${items3.length} \u6761\uFF09\u3002\u8FD9\u4E0D\u662F ad exclusions\uFF0C\u4E5F\u4E0D\u662F\u7CFB\u5217\u7EA7 IP\u3002
|
|
120671
|
+
`);
|
|
120672
|
+
printCliTable(
|
|
120673
|
+
items3.map((item) => ({
|
|
120674
|
+
id: field4(item, "criterionId", "CriterionId"),
|
|
120675
|
+
ip: field4(item, "ipAddress", "IpAddress")
|
|
120676
|
+
})),
|
|
120677
|
+
[
|
|
120678
|
+
{ key: "id", header: "id" },
|
|
120679
|
+
{ key: "ip", header: "IP" }
|
|
120680
|
+
]
|
|
120681
|
+
);
|
|
120682
|
+
console.log();
|
|
120683
|
+
}
|
|
120684
|
+
async function runAdIpExclusionsAdd(opts) {
|
|
120685
|
+
let ipAddress;
|
|
120686
|
+
try {
|
|
120687
|
+
ipAddress = assertIpv4OrCidr(opts.ip);
|
|
120688
|
+
} catch (err) {
|
|
120689
|
+
fail2(err, "\u53C2\u6570");
|
|
120690
|
+
}
|
|
120691
|
+
const { config, base: base2, account } = accountBase2(opts);
|
|
120692
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions`;
|
|
120693
|
+
try {
|
|
120694
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ ipAddress }) }, opts.verbose);
|
|
120695
|
+
} catch (err) {
|
|
120696
|
+
fail2(err, "\u6DFB\u52A0 IP \u6392\u9664\u5931\u8D25");
|
|
120697
|
+
}
|
|
120698
|
+
console.log(`
|
|
120699
|
+
\u2705 \u5DF2\u6DFB\u52A0\u8D26\u6237\u7EA7 IP \u6392\u9664 ${ipAddress}
|
|
120700
|
+
`);
|
|
120701
|
+
}
|
|
120702
|
+
async function runAdIpExclusionsRemove(opts) {
|
|
120703
|
+
const criterionId = (opts.criterionId ?? "").trim();
|
|
120704
|
+
if (!/^\d+$/.test(criterionId)) fail2(new Error("--criterion-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
120705
|
+
const { config, base: base2, account } = accountBase2(opts);
|
|
120706
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions/${criterionId}`;
|
|
120707
|
+
try {
|
|
120708
|
+
await apiDeleteRaw(url, config, { verbose: opts.verbose });
|
|
120709
|
+
} catch (err) {
|
|
120710
|
+
fail2(err, "\u5220\u9664 IP \u6392\u9664\u5931\u8D25");
|
|
120711
|
+
}
|
|
120712
|
+
console.log(`
|
|
120713
|
+
\u2705 \u5DF2\u5220\u9664\u8D26\u6237\u7EA7 IP \u6392\u9664 ${criterionId}
|
|
120714
|
+
`);
|
|
120715
|
+
}
|
|
120716
|
+
|
|
119602
120717
|
// src/commands/ad/extension.ts
|
|
119603
120718
|
init_auth();
|
|
119604
120719
|
import { readFileSync as readFileSync8 } from "fs";
|
|
@@ -121603,13 +122718,13 @@ function livePoolHasText(pool, text4) {
|
|
|
121603
122718
|
function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
|
|
121604
122719
|
const base2 = `${groupPath}.AdsForBatchJob[${adIndex}]`;
|
|
121605
122720
|
const out = [];
|
|
121606
|
-
const push = (kind,
|
|
122721
|
+
const push = (kind, field5, raw) => {
|
|
121607
122722
|
if (typeof raw !== "string" || !raw.trim()) return;
|
|
121608
122723
|
out.push({
|
|
121609
|
-
path: `${base2}.${
|
|
122724
|
+
path: `${base2}.${field5}`,
|
|
121610
122725
|
adGroupName,
|
|
121611
122726
|
kind,
|
|
121612
|
-
field,
|
|
122727
|
+
field: field5,
|
|
121613
122728
|
text: raw.trim()
|
|
121614
122729
|
});
|
|
121615
122730
|
};
|
|
@@ -123348,10 +124463,10 @@ function validateTextLengths(errors, lengthViolations, texts, arrayField, kind,
|
|
|
123348
124463
|
texts.forEach((text4, i) => {
|
|
123349
124464
|
const len = calcGoogleCharLength(text4);
|
|
123350
124465
|
if (len > limit) {
|
|
123351
|
-
const
|
|
124466
|
+
const field5 = `${arrayField}[${i}]`;
|
|
123352
124467
|
pushLengthViolation(lengthViolations, {
|
|
123353
|
-
path:
|
|
123354
|
-
field,
|
|
124468
|
+
path: field5,
|
|
124469
|
+
field: field5,
|
|
123355
124470
|
kind,
|
|
123356
124471
|
limit,
|
|
123357
124472
|
actual: len,
|
|
@@ -127134,7 +128249,7 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
|
|
|
127134
128249
|
// src/commands/ad/demand-gen.ts
|
|
127135
128250
|
init_shared();
|
|
127136
128251
|
var MONEY_HINT = "budget / targetCpa_BidingAmount / minimumDailyBudget \u662F\u5206\uFF08500 = 5 \u5143\uFF09\u3002\u770B\u65C1\u8FB9\u7684 *Yuan\u3002\u5199\u5165 --budget / JSON \u586B\u5143\uFF1B\u82E5\u540C\u65F6\u6709 *Yuan\uFF0C\u4EE5 Yuan \u4E3A\u51C6\u3002targetRoas \u662F\u6BD4\u7387\u3002\u62A5\u8868 spend \u5DF2\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u4E0D\u8981\u62FF\u53BB\u5F53\u9884\u7B97\u3002";
|
|
127137
|
-
function
|
|
128252
|
+
function fail3(message) {
|
|
127138
128253
|
console.error(`
|
|
127139
128254
|
\u274C ${message}
|
|
127140
128255
|
`);
|
|
@@ -127154,7 +128269,7 @@ async function emit(opts, section, commandLabel, payload, idSuffix) {
|
|
|
127154
128269
|
}
|
|
127155
128270
|
function printIssues(issues) {
|
|
127156
128271
|
if (issues.length === 0) return;
|
|
127157
|
-
|
|
128272
|
+
fail3(issues.join("\n"));
|
|
127158
128273
|
}
|
|
127159
128274
|
function loadBody(configFile) {
|
|
127160
128275
|
return stripMetaKeys(loadPmaxJsonFile(configFile));
|
|
@@ -127237,7 +128352,7 @@ async function postCreate(opts, path58, commandLabel) {
|
|
|
127237
128352
|
body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
|
|
127238
128353
|
body = prepareCreateBody(body);
|
|
127239
128354
|
} catch (err) {
|
|
127240
|
-
|
|
128355
|
+
fail3(err instanceof Error ? err.message : String(err));
|
|
127241
128356
|
}
|
|
127242
128357
|
printIssues(demandGenCreateIssues(body));
|
|
127243
128358
|
const url = path58 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path58}` : demandGenCollectionUrl(googleApiUrl, accountId);
|
|
@@ -127250,7 +128365,7 @@ async function postCreate(opts, path58, commandLabel) {
|
|
|
127250
128365
|
opts.verbose
|
|
127251
128366
|
);
|
|
127252
128367
|
} catch (err) {
|
|
127253
|
-
|
|
128368
|
+
fail3(explainCreateError(err));
|
|
127254
128369
|
}
|
|
127255
128370
|
const payload = decorateDemandGenRead(data);
|
|
127256
128371
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path58 || "create"}`, commandLabel, payload, accountId)) {
|
|
@@ -127270,7 +128385,7 @@ async function runDemandGenList(opts) {
|
|
|
127270
128385
|
try {
|
|
127271
128386
|
data = await pmaxApiFetch(demandGenCollectionUrl(googleApiUrl, accountId), config, {}, opts.verbose);
|
|
127272
128387
|
} catch (err) {
|
|
127273
|
-
|
|
128388
|
+
fail3(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127274
128389
|
}
|
|
127275
128390
|
const payload = {
|
|
127276
128391
|
items: decorateDemandGenRead(data),
|
|
@@ -127307,7 +128422,7 @@ async function runDemandGenGet(opts) {
|
|
|
127307
128422
|
opts.verbose
|
|
127308
128423
|
);
|
|
127309
128424
|
} catch (err) {
|
|
127310
|
-
|
|
128425
|
+
fail3(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127311
128426
|
}
|
|
127312
128427
|
const payload = asRecord5(decorateDemandGenRead(data));
|
|
127313
128428
|
payload["agentHint"] = MONEY_HINT;
|
|
@@ -127336,7 +128451,7 @@ async function runDemandGenMinimumBudget(opts) {
|
|
|
127336
128451
|
opts.verbose
|
|
127337
128452
|
);
|
|
127338
128453
|
} catch (err) {
|
|
127339
|
-
|
|
128454
|
+
fail3(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127340
128455
|
}
|
|
127341
128456
|
const payload = decorateDemandGenRead(data);
|
|
127342
128457
|
if (await emit(
|
|
@@ -127368,7 +128483,7 @@ async function runDemandGenConversions(opts) {
|
|
|
127368
128483
|
opts.verbose
|
|
127369
128484
|
);
|
|
127370
128485
|
} catch (err) {
|
|
127371
|
-
|
|
128486
|
+
fail3(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127372
128487
|
}
|
|
127373
128488
|
if (await emit(
|
|
127374
128489
|
{ ...opts, account: accountId },
|
|
@@ -127401,7 +128516,7 @@ async function runDemandGenDraft(opts) {
|
|
|
127401
128516
|
opts.verbose
|
|
127402
128517
|
);
|
|
127403
128518
|
} catch (err) {
|
|
127404
|
-
|
|
128519
|
+
fail3(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127405
128520
|
}
|
|
127406
128521
|
const payload = decorateDemandGenRead(data);
|
|
127407
128522
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-draft", "ad demand-gen draft", payload, accountId)) {
|
|
@@ -127426,7 +128541,7 @@ async function runDemandGenConfirm(opts) {
|
|
|
127426
128541
|
}
|
|
127427
128542
|
function readFlagNumber(value, label2) {
|
|
127428
128543
|
const amount = typeof value === "number" ? value : Number(String(value).trim());
|
|
127429
|
-
if (!Number.isFinite(amount))
|
|
128544
|
+
if (!Number.isFinite(amount)) fail3(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
|
|
127430
128545
|
return amount;
|
|
127431
128546
|
}
|
|
127432
128547
|
async function runDemandGenEdit(opts) {
|
|
@@ -127443,7 +128558,7 @@ async function runDemandGenEdit(opts) {
|
|
|
127443
128558
|
if (opts.name !== void 0) body["name"] = opts.name.trim();
|
|
127444
128559
|
if (opts.status !== void 0) {
|
|
127445
128560
|
const status2 = normalizeCampaignStatus(opts.status);
|
|
127446
|
-
if (!status2)
|
|
128561
|
+
if (!status2) fail3("Campaign status must be Enabled, Paused, or Removed.");
|
|
127447
128562
|
body["statusV2"] = status2;
|
|
127448
128563
|
}
|
|
127449
128564
|
if (opts.budget !== void 0) body["budget"] = readFlagNumber(opts.budget, "\u9884\u7B97");
|
|
@@ -127458,7 +128573,7 @@ async function runDemandGenEdit(opts) {
|
|
|
127458
128573
|
body = normalizeDemandGenMoneyForWrite(body);
|
|
127459
128574
|
}
|
|
127460
128575
|
if (Object.keys(body).length === 0) {
|
|
127461
|
-
|
|
128576
|
+
fail3("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
|
|
127462
128577
|
}
|
|
127463
128578
|
const status = normalizeCampaignStatus(body["statusV2"]);
|
|
127464
128579
|
if (status) body["statusV2"] = status;
|
|
@@ -127476,7 +128591,7 @@ async function runDemandGenEdit(opts) {
|
|
|
127476
128591
|
});
|
|
127477
128592
|
}
|
|
127478
128593
|
if (body["automatic"] === true) {
|
|
127479
|
-
|
|
128594
|
+
fail3("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
|
|
127480
128595
|
}
|
|
127481
128596
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
127482
128597
|
try {
|
|
@@ -127487,7 +128602,7 @@ async function runDemandGenEdit(opts) {
|
|
|
127487
128602
|
opts.verbose
|
|
127488
128603
|
);
|
|
127489
128604
|
} catch (err) {
|
|
127490
|
-
|
|
128605
|
+
fail3(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127491
128606
|
}
|
|
127492
128607
|
const payload = { ok: true, campaignId, patch: body };
|
|
127493
128608
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
|
|
@@ -127506,20 +128621,20 @@ async function runDemandGenContent(opts) {
|
|
|
127506
128621
|
delete body["targetedLocations"];
|
|
127507
128622
|
delete body["targetedLanguages"];
|
|
127508
128623
|
}
|
|
127509
|
-
if (Object.keys(body).length === 0)
|
|
128624
|
+
if (Object.keys(body).length === 0) fail3("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
|
|
127510
128625
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
127511
128626
|
let next = body;
|
|
127512
128627
|
try {
|
|
127513
128628
|
next = await attachImages(opts.configFile, body, accountId, config, googleApiUrl, opts.verbose);
|
|
127514
128629
|
} catch (err) {
|
|
127515
|
-
|
|
128630
|
+
fail3(err instanceof Error ? err.message : String(err));
|
|
127516
128631
|
}
|
|
127517
128632
|
delete next["imagePaths"];
|
|
127518
128633
|
const url = opts.adId?.trim() ? demandGenAdUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), opts.adId.trim(), "content") : demandGenAdGroupUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), "content");
|
|
127519
128634
|
try {
|
|
127520
128635
|
await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify(next) }, opts.verbose);
|
|
127521
128636
|
} catch (err) {
|
|
127522
|
-
|
|
128637
|
+
fail3(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127523
128638
|
}
|
|
127524
128639
|
const payload = { ok: true, campaignId: opts.campaignId, adGroupId: opts.adGroupId, adId: opts.adId ?? null };
|
|
127525
128640
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-content", "ad demand-gen content", payload)) return;
|
|
@@ -127531,7 +128646,7 @@ async function runDemandGenChannels(opts) {
|
|
|
127531
128646
|
const hasStrategy = Boolean(opts.strategy?.trim());
|
|
127532
128647
|
const hasSelected = Boolean(opts.selected?.trim());
|
|
127533
128648
|
if (hasStrategy === hasSelected) {
|
|
127534
|
-
|
|
128649
|
+
fail3("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
|
|
127535
128650
|
}
|
|
127536
128651
|
const body = {};
|
|
127537
128652
|
if (hasStrategy) body["channelStrategy"] = opts.strategy.trim();
|
|
@@ -127539,7 +128654,7 @@ async function runDemandGenChannels(opts) {
|
|
|
127539
128654
|
try {
|
|
127540
128655
|
body["selectedChannels"] = buildSelectedChannels(opts.selected.split(","));
|
|
127541
128656
|
} catch (err) {
|
|
127542
|
-
|
|
128657
|
+
fail3(err instanceof Error ? err.message : String(err));
|
|
127543
128658
|
}
|
|
127544
128659
|
}
|
|
127545
128660
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -127553,7 +128668,7 @@ async function runDemandGenChannels(opts) {
|
|
|
127553
128668
|
try {
|
|
127554
128669
|
await pmaxApiFetch(url, config, { method: "PATCH", body: JSON.stringify(body) }, opts.verbose);
|
|
127555
128670
|
} catch (err) {
|
|
127556
|
-
|
|
128671
|
+
fail3(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127557
128672
|
}
|
|
127558
128673
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-channels", "ad demand-gen channels", { ok: true, patch: body })) {
|
|
127559
128674
|
return;
|
|
@@ -127564,7 +128679,7 @@ async function runDemandGenChannels(opts) {
|
|
|
127564
128679
|
async function putStatus(opts, kind) {
|
|
127565
128680
|
const status = normalizeAdStatus(opts.status);
|
|
127566
128681
|
if (!status) {
|
|
127567
|
-
|
|
128682
|
+
fail3("\u5E7F\u544A\u548C\u5E7F\u544A\u7EC4\u53EA\u63A5\u53D7 Enabled \u6216 Paused\u3002\u4E0D\u8981\u7528\u5B83\u542F\u7528\u7CFB\u5217\uFF1B\u5220\u5149\u4F1A 400\uFF0C\u53EA\u60F3\u505C\u6295\u7528 Paused\u3002");
|
|
127568
128683
|
}
|
|
127569
128684
|
const accountId = requireAccountId(opts.account);
|
|
127570
128685
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -127590,7 +128705,7 @@ async function putStatus(opts, kind) {
|
|
|
127590
128705
|
opts.verbose
|
|
127591
128706
|
);
|
|
127592
128707
|
} catch (err) {
|
|
127593
|
-
|
|
128708
|
+
fail3(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127594
128709
|
}
|
|
127595
128710
|
console.log(`
|
|
127596
128711
|
\u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
|
|
@@ -127605,7 +128720,7 @@ async function runDemandGenAdStatus(opts) {
|
|
|
127605
128720
|
}
|
|
127606
128721
|
async function runDemandGenAdGroupRename(opts) {
|
|
127607
128722
|
const name2 = opts.name.trim();
|
|
127608
|
-
if (!name2 || name2.length > 255)
|
|
128723
|
+
if (!name2 || name2.length > 255) fail3("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
|
|
127609
128724
|
const accountId = requireAccountId(opts.account);
|
|
127610
128725
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
127611
128726
|
const url = demandGenAdGroupUrl(
|
|
@@ -127618,7 +128733,7 @@ async function runDemandGenAdGroupRename(opts) {
|
|
|
127618
128733
|
try {
|
|
127619
128734
|
await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify({ name: name2 }) }, opts.verbose);
|
|
127620
128735
|
} catch (err) {
|
|
127621
|
-
|
|
128736
|
+
fail3(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127622
128737
|
}
|
|
127623
128738
|
console.log(`
|
|
127624
128739
|
\u2705 \u5E7F\u544A\u7EC4\u5DF2\u6539\u540D\u4E3A ${name2}
|
|
@@ -127628,7 +128743,7 @@ async function runDemandGenAdGroupRename(opts) {
|
|
|
127628
128743
|
async function runDemandGenAudience(opts) {
|
|
127629
128744
|
const audienceResourceName = opts.resourceName.trim();
|
|
127630
128745
|
if (!audienceResourceName.includes("/audiences/")) {
|
|
127631
|
-
|
|
128746
|
+
fail3("Audience resource name must be customers/{id}/audiences/{audienceId}.");
|
|
127632
128747
|
}
|
|
127633
128748
|
const accountId = requireAccountId(opts.account);
|
|
127634
128749
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -127647,7 +128762,7 @@ async function runDemandGenAudience(opts) {
|
|
|
127647
128762
|
opts.verbose
|
|
127648
128763
|
);
|
|
127649
128764
|
} catch (err) {
|
|
127650
|
-
|
|
128765
|
+
fail3(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127651
128766
|
}
|
|
127652
128767
|
console.log("\n\u2705 \u5E7F\u544A\u7EC4\u53D7\u4F17\u5DF2\u66FF\u6362\u3002\u4E00\u4E2A\u5E7F\u544A\u7EC4\u53EA\u80FD\u7ED1\u4E00\u4E2A Audience\u3002\n");
|
|
127653
128768
|
});
|
|
@@ -127655,7 +128770,7 @@ async function runDemandGenAudience(opts) {
|
|
|
127655
128770
|
async function runDemandGenAudienceKeywords(opts) {
|
|
127656
128771
|
const audienceKeywords = opts.keywords.split(",").map((item) => item.trim()).filter(Boolean);
|
|
127657
128772
|
if (audienceKeywords.length < 1 || audienceKeywords.length > 10) {
|
|
127658
|
-
|
|
128773
|
+
fail3("Audience keyword count must be between 1 and 10.");
|
|
127659
128774
|
}
|
|
127660
128775
|
const accountId = requireAccountId(opts.account);
|
|
127661
128776
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -127674,7 +128789,7 @@ async function runDemandGenAudienceKeywords(opts) {
|
|
|
127674
128789
|
opts.verbose
|
|
127675
128790
|
);
|
|
127676
128791
|
} catch (err) {
|
|
127677
|
-
|
|
128792
|
+
fail3(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127678
128793
|
}
|
|
127679
128794
|
console.log("\n\u2705 \u641C\u7D22\u81EA\u5B9A\u4E49\u53D7\u4F17\u7684\u8BCD\u5DF2\u6574\u4EFD\u66FF\u6362\n");
|
|
127680
128795
|
});
|
|
@@ -127687,7 +128802,7 @@ async function postChild(opts, kind) {
|
|
|
127687
128802
|
try {
|
|
127688
128803
|
body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
|
|
127689
128804
|
} catch (err) {
|
|
127690
|
-
|
|
128805
|
+
fail3(err instanceof Error ? err.message : String(err));
|
|
127691
128806
|
}
|
|
127692
128807
|
delete body["account"];
|
|
127693
128808
|
delete body["imagePaths"];
|
|
@@ -127696,7 +128811,7 @@ async function postChild(opts, kind) {
|
|
|
127696
128811
|
try {
|
|
127697
128812
|
data = await pmaxApiFetch(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
127698
128813
|
} catch (err) {
|
|
127699
|
-
|
|
128814
|
+
fail3(err instanceof Error ? err.message : String(err));
|
|
127700
128815
|
}
|
|
127701
128816
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-add-${kind}`, `ad demand-gen add-${kind}`, data)) {
|
|
127702
128817
|
return;
|
|
@@ -127731,7 +128846,7 @@ async function runDemandGenDeleteAd(opts) {
|
|
|
127731
128846
|
try {
|
|
127732
128847
|
await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
|
|
127733
128848
|
} catch (err) {
|
|
127734
|
-
|
|
128849
|
+
fail3(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127735
128850
|
}
|
|
127736
128851
|
console.log("\n\u2705 \u5E7F\u544A\u5DF2\u5220\u9664\n");
|
|
127737
128852
|
});
|
|
@@ -127752,7 +128867,7 @@ async function runDemandGenDeleteAdGroup(opts) {
|
|
|
127752
128867
|
try {
|
|
127753
128868
|
await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
|
|
127754
128869
|
} catch (err) {
|
|
127755
|
-
|
|
128870
|
+
fail3(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127756
128871
|
}
|
|
127757
128872
|
console.log("\n\u2705 \u5E7F\u544A\u7EC4\u5DF2\u5220\u9664\n");
|
|
127758
128873
|
});
|
|
@@ -127771,7 +128886,7 @@ async function runDemandGenReport(opts) {
|
|
|
127771
128886
|
opts.verbose
|
|
127772
128887
|
);
|
|
127773
128888
|
} catch (err) {
|
|
127774
|
-
|
|
128889
|
+
fail3(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127775
128890
|
}
|
|
127776
128891
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-report", "ad demand-gen report", data, opts.campaignId)) {
|
|
127777
128892
|
return;
|
|
@@ -127795,7 +128910,7 @@ async function runDemandGenConversionsValidate(opts) {
|
|
|
127795
128910
|
opts.verbose
|
|
127796
128911
|
);
|
|
127797
128912
|
} catch (err) {
|
|
127798
|
-
|
|
128913
|
+
fail3(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
127799
128914
|
}
|
|
127800
128915
|
if (await emit(
|
|
127801
128916
|
{ ...opts, account: accountId },
|
|
@@ -129047,7 +130162,7 @@ function register21(program2) {
|
|
|
129047
130162
|
verbose: opts.verbose
|
|
129048
130163
|
});
|
|
129049
130164
|
});
|
|
129050
|
-
adCmd.command("search-terms").description("\u67E5\u8BE2\u641C\u7D22\u5B57\u8BCD\u62A5\u544A\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF09").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4 30 \u5929\u524D\uFF09").option("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4\u4ECA\u5929\uFF09").option("-t, --token <token>", "Auth Token").option(
|
|
130165
|
+
adCmd.command("search-terms").description("\u67E5\u8BE2\u641C\u7D22\u5B57\u8BCD\u62A5\u544A\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF09\u3002PMax \u641C\u7D22\u8BCD\u7528 ad pmax-search-terms").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4 30 \u5929\u524D\uFF09").option("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4\u4ECA\u5929\uFF09").option("-t, --token <token>", "Auth Token").option(
|
|
129051
130166
|
"--json-out <path>",
|
|
129052
130167
|
"\u843D\u76D8\uFF08\u76EE\u5F55\u6216 *.json \u6587\u4EF6\u8DEF\u5F84\uFF09\u5E76\u66F4\u65B0 cli-manifest[-<\u67E5\u8BE2id>].json\uFF1B\u76EE\u5F55\u6A21\u5F0F\u6587\u4EF6\u540D\u4E3A `<section>[-<\u67E5\u8BE2id>].json`\uFF1Bstdout \u4E00\u884C\u6458\u8981 JSON\uFF0C\u542B outlineFile\uFF08TS \u5F0F\u7C7B\u578B\u5728 `*.outline.txt`\uFF09",
|
|
129053
130168
|
void 0
|
|
@@ -129239,6 +130354,146 @@ function register21(program2) {
|
|
|
129239
130354
|
}
|
|
129240
130355
|
);
|
|
129241
130356
|
registerDemandGen(adCmd);
|
|
130357
|
+
registerAccountOps(adCmd);
|
|
130358
|
+
registerProtection(adCmd);
|
|
130359
|
+
}
|
|
130360
|
+
function registerAccountOps(adCmd) {
|
|
130361
|
+
const exclusions = adCmd.command("exclusions").description(
|
|
130362
|
+
"\u8D26\u6237\u7EA7\u5185\u5BB9\u9002\u5B9C\u6027\u6392\u9664\uFF08\u654F\u611F\u5185\u5BB9\u3001\u7C7B\u578B\u548C\u6807\u7B7E\u3001\u5185\u5BB9\u4E3B\u9898\u3001\u7F51\u7AD9\u3001YouTube\u3001\u5E94\u7528\u3001\u5E94\u7528\u7C7B\u522B\uFF09\u3002\u5168\u8D26\u6237\u751F\u6548\u3002\u4E0D\u662F\u5C55\u793A\u5E7F\u544A\u521B\u5EFA\uFF0C\u4E5F\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\u6216\u5185\u5BB9\u5173\u952E\u5B57"
|
|
130363
|
+
);
|
|
130364
|
+
exclusions.command("list").description("\u5217\u51FA\u5DF2\u751F\u6548\u7684\u8D26\u6237\u7EA7\u5185\u5BB9\u6392\u9664").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--type <type>", "content-label | placement | youtube-channel | youtube-video | app | app-category").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130365
|
+
await runAdExclusionsList(opts);
|
|
130366
|
+
});
|
|
130367
|
+
exclusions.command("add").description("\u6DFB\u52A0\u4E00\u6761\u8D26\u6237\u7EA7\u6392\u9664\u3002\u4E00\u6B21\u4E00\u79CD\u7C7B\u578B\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list\uFF0C\u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--type <type>", "content-label | placement | youtube-channel | youtube-video | app | app-category").option("--content-label <name>", "\u5185\u5BB9\u6807\u7B7E proto \u540D\uFF0C\u6765\u81EA content-labels\uFF0C\u5982 BRAND_SUITABILITY_GAMES_FIGHTING").option("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u7AD9").option("--channel-id <id>", "YouTube \u9891\u9053 ID").option("--video-id <id>", "YouTube \u89C6\u9891 ID").option("--app-id <id>", "\u5E94\u7528 ID\uFF1A1-\u6570\u5B57 \u6216 2-\u5305\u540D").option("--app-category-id <id>", "\u5E94\u7528\u7C7B\u522B\u6570\u5B57 id\uFF0C\u6765\u81EA app-categories").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130368
|
+
await runAdExclusionsAdd({
|
|
130369
|
+
token: opts.token,
|
|
130370
|
+
account: opts.account,
|
|
130371
|
+
type: opts.type ?? "",
|
|
130372
|
+
contentLabel: opts.contentLabel,
|
|
130373
|
+
url: opts.url,
|
|
130374
|
+
channelId: opts.channelId,
|
|
130375
|
+
videoId: opts.videoId,
|
|
130376
|
+
appId: opts.appId,
|
|
130377
|
+
appCategoryId: opts.appCategoryId,
|
|
130378
|
+
jsonOut: opts.jsonOut,
|
|
130379
|
+
verbose: opts.verbose
|
|
130380
|
+
});
|
|
130381
|
+
});
|
|
130382
|
+
exclusions.command("remove").description("\u6309 list \u8FD4\u56DE\u7684 criterionId \u5220\u9664\u4E00\u6761\u8D26\u6237\u7EA7\u6392\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--criterion-id <id>", "exclusions list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130383
|
+
await runAdExclusionsRemove({
|
|
130384
|
+
token: opts.token,
|
|
130385
|
+
account: opts.account,
|
|
130386
|
+
criterionId: opts.criterionId ?? "",
|
|
130387
|
+
verbose: opts.verbose
|
|
130388
|
+
});
|
|
130389
|
+
});
|
|
130390
|
+
exclusions.command("content-labels").description("\u5185\u5BB9\u6807\u7B7E\u76EE\u5F55\u3002\u6E38\u620F\uFF08\u683C\u6597\uFF09\u662F BRAND_SUITABILITY_GAMES_FIGHTING\uFF0C\u4E0D\u662F Topic").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130391
|
+
await runAdExclusionContentLabels(opts);
|
|
130392
|
+
});
|
|
130393
|
+
exclusions.command("app-categories").description("\u5E94\u7528\u7C7B\u522B\u5E38\u91CF\u3002\u6761\u6570\u4EE5\u67E5\u8BE2\u4E3A\u51C6\u3002\u6392\u9664\u524D\u5148\u62FF id").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130394
|
+
await runAdExclusionAppCategories(opts);
|
|
130395
|
+
});
|
|
130396
|
+
adCmd.command("placements").description("\u7248\u4F4D\u82B1\u8D39\uFF08\u7F51\u7AD9 / \u5E94\u7528 / \u9891\u9053\uFF09\u3002\u6392\u9664\u7248\u4F4D\u524D\u5148\u770B\u8FD9\u5F20\u8868\u3002\u4E0D\u662F ad demand-gen report").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130397
|
+
await runAdPlacements(opts);
|
|
130398
|
+
});
|
|
130399
|
+
adCmd.command("conversion-goals").description("\u7CFB\u5217\u5B9E\u9645\u8BA1\u5165\u51FA\u4EF7\u7684\u8F6C\u5316\u76EE\u6807\u3002\u53EA\u8BFB\u3002CPA \u5F02\u5E38\u65F6\u5148\u770B\u8FD9\u91CC").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--campaign-id <id>", "\u53EA\u770B\u4E00\u4E2A\u7CFB\u5217").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130400
|
+
await runAdConversionGoals(opts);
|
|
130401
|
+
});
|
|
130402
|
+
adCmd.command("changes").description("\u64CD\u4F5C\u8BB0\u5F55\u3002\u53EA\u8BFB\uFF0C\u533A\u95F4\u6700\u591A 30 \u5929\u3002\u7A7A\u5217\u8868\u8868\u793A\u6CA1\u6709\u8BB0\u5F55").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--start <date>", "YYYY-MM-DD").requiredOption("--end <date>", "YYYY-MM-DD").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130403
|
+
await runAdChanges({
|
|
130404
|
+
token: opts.token,
|
|
130405
|
+
account: opts.account,
|
|
130406
|
+
start: opts.start ?? "",
|
|
130407
|
+
end: opts.end ?? "",
|
|
130408
|
+
jsonOut: opts.jsonOut,
|
|
130409
|
+
verbose: opts.verbose
|
|
130410
|
+
});
|
|
130411
|
+
});
|
|
130412
|
+
const negativeList = adCmd.command("negative-list").description(
|
|
130413
|
+
"\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD\u5171\u4EAB\u5217\u8868\uFF08\u6BCF\u6237\u4E00\u4E2A\uFF09\u3002\u6321\u641C\u7D22\u67E5\u8BE2\uFF0C\u4E0D\u7BA1 YouTube / \u5C55\u793A\u5185\u5BB9\u3002\u5185\u5BB9\u5173\u952E\u5B57\u6CA1\u6709\u516C\u5F00\u63A5\u53E3"
|
|
130414
|
+
);
|
|
130415
|
+
negativeList.command("list").description("\u5217\u51FA\u5DF2\u6302\u63A5\u7684\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130416
|
+
await runAdNegativeList(opts);
|
|
130417
|
+
});
|
|
130418
|
+
negativeList.command("add").description("\u5F80\u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u52A0\u8BCD\u3002\u672A\u6302\u63A5\u65F6\u540E\u7AEF\u4F1A\u5148\u6302\u63A5\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--keywords <kw1,kw2>", "\u9017\u53F7\u5206\u9694", (v) => parseKeywordsCsv(v)).option("--keywords-file <path>", "\u8BCD\u6587\u4EF6").option("--match-type <type>", "Broad | Phrase | Exact").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130419
|
+
await runAdNegativeListAdd({
|
|
130420
|
+
token: opts.token,
|
|
130421
|
+
account: opts.account,
|
|
130422
|
+
keywords: opts.keywords,
|
|
130423
|
+
keywordsFile: opts.keywordsFile,
|
|
130424
|
+
matchType: parseOptionalMatchType(opts.matchType),
|
|
130425
|
+
jsonOut: opts.jsonOut,
|
|
130426
|
+
verbose: opts.verbose
|
|
130427
|
+
});
|
|
130428
|
+
});
|
|
130429
|
+
negativeList.command("remove").description("\u6309 list \u7684 id \u5220\u9664\u4E00\u6761\u8D26\u6237\u7EA7\u5426\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <id>", "\u5426\u8BCD id").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130430
|
+
await runAdNegativeListRemove({
|
|
130431
|
+
token: opts.token,
|
|
130432
|
+
account: opts.account,
|
|
130433
|
+
id: opts.id ?? "",
|
|
130434
|
+
verbose: opts.verbose
|
|
130435
|
+
});
|
|
130436
|
+
});
|
|
130437
|
+
negativeList.command("attach").description("\u786E\u4FDD\u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5\u3002\u4E0D\u52A0\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130438
|
+
await runAdNegativeListAttach(opts);
|
|
130439
|
+
});
|
|
130440
|
+
}
|
|
130441
|
+
function registerProtection(adCmd) {
|
|
130442
|
+
adCmd.command("pmax-search-terms").description("PMax \u641C\u7D22\u8BCD\u3002\u5FC5\u987B\u6307\u5B9A\u4E00\u4E2A\u7CFB\u5217\u3002\u4E0D\u662F ad search-terms").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130443
|
+
await runAdPmaxSearchTerms(opts);
|
|
130444
|
+
});
|
|
130445
|
+
const brands = adCmd.command("pmax-brands").description("PMax \u54C1\u724C\u6392\u9664\u3002id \u53EA\u80FD\u6765\u81EA search\u3002\u6302\u63A5\u53EA\u4F5C\u7528\u4E8E PMax \u7CFB\u5217");
|
|
130446
|
+
brands.command("search").description("\u6309\u524D\u7F00\u67E5\u54C1\u724C\u5EFA\u8BAE").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--prefix <text>", "\u54C1\u724C\u540D\u524D\u7F00").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130447
|
+
await runAdPmaxBrandsSearch(opts);
|
|
130448
|
+
});
|
|
130449
|
+
brands.command("list").description("\u5DF2\u6709\u54C1\u724C\u548C\u5DF2\u6302\u4E0A\u7684\u7CFB\u5217").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130450
|
+
await runAdPmaxBrandsList(opts);
|
|
130451
|
+
});
|
|
130452
|
+
brands.command("add").description("\u628A search \u8FD4\u56DE\u7684\u54C1\u724C id \u5199\u5165\u5217\u8868\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--entity-id <id>", "pmax-brands search \u7684 id").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130453
|
+
await runAdPmaxBrandsAdd(opts);
|
|
130454
|
+
});
|
|
130455
|
+
brands.command("attach").description("\u628A\u54C1\u724C\u5217\u8868\u6302\u5230\u4E00\u4E2A PMax \u7CFB\u5217\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").option("--shared-set-id <id>", "\u54C1\u724C\u5217\u8868 id\uFF0C\u4E0D\u4F20\u5219\u7528\u8D26\u6237\u91CC\u5DF2\u6709\u7684\u90A3\u4EFD").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130456
|
+
await runAdPmaxBrandsAttach(opts);
|
|
130457
|
+
});
|
|
130458
|
+
brands.command("detach").description("\u4ECE\u7CFB\u5217\u5378\u4E0B\u54C1\u724C\u5217\u8868\u3002\u4E0D\u5220\u9664\u5217\u8868\u91CC\u7684\u54C1\u724C\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u91CC\u5DF2\u6302\u7CFB\u5217\u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130459
|
+
await runAdPmaxBrandsDetach(opts);
|
|
130460
|
+
});
|
|
130461
|
+
const negatives = adCmd.command("pmax-negatives").description("PMax \u7CFB\u5217\u5426\u8BCD\u3002\u4E0D\u662F ad negative-list\u3002\u53EA\u63A5\u53D7 PMax \u7CFB\u5217");
|
|
130462
|
+
negatives.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130463
|
+
await runAdPmaxNegativesList(opts);
|
|
130464
|
+
});
|
|
130465
|
+
negatives.command("add").description("\u52A0\u4E00\u6761\u7CFB\u5217\u5426\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--text <keyword>", "\u4E00\u4E2A\u8BCD").option("--match-type <type>", "Broad | Phrase | Exact\uFF0C\u9ED8\u8BA4 Broad").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130466
|
+
await runAdPmaxNegativesAdd(opts);
|
|
130467
|
+
});
|
|
130468
|
+
negatives.command("remove").description("\u6309 list \u7684 criterionId \u5220\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130469
|
+
await runAdPmaxNegativesRemove(opts);
|
|
130470
|
+
});
|
|
130471
|
+
const urls = adCmd.command("pmax-urls").description("PMax \u7F51\u5740\u6392\u9664\u3002\u4E0D\u662F pmax-edit \u7684\u7F51\u5740\u6269\u5C55\u5F00\u5173");
|
|
130472
|
+
urls.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130473
|
+
await runAdPmaxUrlsList(opts);
|
|
130474
|
+
});
|
|
130475
|
+
urls.command("add").description("\u6392\u9664\u4E00\u4E2A URL\u3002EQUALS \u6216 CONTAINS\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u5740").requiredOption("--operator <op>", "EQUALS | CONTAINS").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130476
|
+
await runAdPmaxUrlsAdd(opts);
|
|
130477
|
+
});
|
|
130478
|
+
urls.command("remove").description("\u6309 criterionId \u5220\u9664\u4E00\u6761\u7F51\u5740\u6392\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130479
|
+
await runAdPmaxUrlsRemove(opts);
|
|
130480
|
+
});
|
|
130481
|
+
adCmd.command("rsa-assets").description("\u641C\u7D22\u5E7F\u544A RSA \u7D20\u6750\u8868\u73B0\u3002\u7528\u6765\u770B\u54EA\u6761\u6807\u9898\u3001\u63CF\u8FF0\u5728\u82B1\u94B1").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130482
|
+
await runAdRsaAssets(opts);
|
|
130483
|
+
});
|
|
130484
|
+
adCmd.command("recommendation-subscriptions").description("\u81EA\u52A8\u5E94\u7528\u5EFA\u8BAE\u7684\u8BA2\u9605\u72B6\u6001\u3002\u53EA\u8BFB\uFF0C\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3").allowExcessArguments(false).requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130485
|
+
await runAdRecommendationSubscriptions(opts);
|
|
130486
|
+
});
|
|
130487
|
+
const ips = adCmd.command("ip-exclusions").description("\u8D26\u6237\u7EA7 IP \u6392\u9664\u3002\u4E0D\u662F\u5185\u5BB9\u6392\u9664\uFF0C\u4E5F\u4E0D\u662F\u7CFB\u5217\u7EA7 IP\u3002\u5168\u8D26\u6237\u751F\u6548");
|
|
130488
|
+
ips.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130489
|
+
await runAdIpExclusionsList(opts);
|
|
130490
|
+
});
|
|
130491
|
+
ips.command("add").description("\u6DFB\u52A0\u4E00\u4E2A IPv4 \u6216 IPv4 CIDR\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--ip <address>", "\u4F8B\u5982 203.0.113.10 \u6216 203.0.113.0/24").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130492
|
+
await runAdIpExclusionsAdd(opts);
|
|
130493
|
+
});
|
|
130494
|
+
ips.command("remove").description("\u6309 list \u7684 criterionId \u5220\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130495
|
+
await runAdIpExclusionsRemove(opts);
|
|
130496
|
+
});
|
|
129242
130497
|
}
|
|
129243
130498
|
|
|
129244
130499
|
// src/commands/meta-ad/account.ts
|
|
@@ -129801,11 +131056,11 @@ function snapshotSupported(targeting) {
|
|
|
129801
131056
|
function diffSnapshots(before, after) {
|
|
129802
131057
|
const fields = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
129803
131058
|
const changes = [];
|
|
129804
|
-
for (const
|
|
129805
|
-
const from = before[
|
|
129806
|
-
const to = after[
|
|
131059
|
+
for (const field5 of fields) {
|
|
131060
|
+
const from = before[field5];
|
|
131061
|
+
const to = after[field5];
|
|
129807
131062
|
const changed = JSON.stringify(from) !== JSON.stringify(to);
|
|
129808
|
-
changes.push({ field, from: from ?? null, to: to ?? null, changed });
|
|
131063
|
+
changes.push({ field: field5, from: from ?? null, to: to ?? null, changed });
|
|
129809
131064
|
}
|
|
129810
131065
|
return changes;
|
|
129811
131066
|
}
|
|
@@ -129912,9 +131167,9 @@ function evaluateAdSetEditReadback(sentBody, actual, readFailed) {
|
|
|
129912
131167
|
for (const key of ADSET_SCALAR_READBACK_KEYS) {
|
|
129913
131168
|
if (sentBody[key] === void 0) continue;
|
|
129914
131169
|
const present = Object.prototype.hasOwnProperty.call(actual, key);
|
|
129915
|
-
const
|
|
129916
|
-
const expected =
|
|
129917
|
-
const actualValue =
|
|
131170
|
+
const money3 = key === "daily_budget" || key === "lifetime_budget" || key === "bid_amount";
|
|
131171
|
+
const expected = money3 ? String(sentBody[key]) : sentBody[key];
|
|
131172
|
+
const actualValue = money3 && actual[key] != null && actual[key] !== "" ? String(actual[key]) : actual[key];
|
|
129918
131173
|
checks.push(fieldCheck(key, expected, actualValue, present));
|
|
129919
131174
|
}
|
|
129920
131175
|
if (isPlainObject(sentBody["targeting"])) {
|
|
@@ -130461,7 +131716,7 @@ async function runMetaAdCreate(opts) {
|
|
|
130461
131716
|
optimizationGoal: cfg.adset.optimizationGoal?.toUpperCase(),
|
|
130462
131717
|
status: omitActive(cfg.adset.status)
|
|
130463
131718
|
};
|
|
130464
|
-
const
|
|
131719
|
+
const money3 = {
|
|
130465
131720
|
dailyBudgetMinor: cfg.adset.dailyBudget != null ? toMinorUnitString(cfg.adset.dailyBudget, currency) : void 0,
|
|
130466
131721
|
lifetimeBudgetMinor: cfg.adset.lifetimeBudget != null ? toMinorUnitString(cfg.adset.lifetimeBudget, currency) : void 0
|
|
130467
131722
|
};
|
|
@@ -130474,7 +131729,7 @@ async function runMetaAdCreate(opts) {
|
|
|
130474
131729
|
adset: baseAdset,
|
|
130475
131730
|
campaignId: progress.campaignId,
|
|
130476
131731
|
pageId,
|
|
130477
|
-
...
|
|
131732
|
+
...money3,
|
|
130478
131733
|
bidAmountMinor: cfg.adset.bidAmount != null ? toMinorUnitString(cfg.adset.bidAmount, currency) : void 0
|
|
130479
131734
|
}),
|
|
130480
131735
|
opts.verbose
|
|
@@ -130520,7 +131775,7 @@ async function runMetaAdCreate(opts) {
|
|
|
130520
131775
|
adset: { ...baseAdset, bidStrategy: decision.bidStrategy },
|
|
130521
131776
|
campaignId: progress.campaignId,
|
|
130522
131777
|
pageId,
|
|
130523
|
-
...
|
|
131778
|
+
...money3,
|
|
130524
131779
|
bidAmountMinor: toMinorUnitString(decision.bidAmount, currency)
|
|
130525
131780
|
}),
|
|
130526
131781
|
opts.verbose
|
|
@@ -140878,7 +142133,7 @@ async function fetchSubdivisions(opts) {
|
|
|
140878
142133
|
}
|
|
140879
142134
|
const url = `${base2}/reporting/media-account/${opts.accountId}/reports/geo/subdivisions?${qs}`;
|
|
140880
142135
|
try {
|
|
140881
|
-
const payload = await apiFetch2(url, opts.config, {
|
|
142136
|
+
const payload = await apiFetch2(url, opts.config, {}, opts.verbose);
|
|
140882
142137
|
const rows = Array.isArray(payload) ? payload : payload && typeof payload === "object" && Array.isArray(payload.countries) ? payload.countries : payload && typeof payload === "object" && Array.isArray(payload.items) ? payload.items : [];
|
|
140883
142138
|
const out = [];
|
|
140884
142139
|
for (const item of rows) {
|
|
@@ -140933,7 +142188,7 @@ async function fetchYoutubeChannel(opts) {
|
|
|
140933
142188
|
if (opts.channelId?.trim()) qs.set("ids", `channel==${opts.channelId.trim()}`);
|
|
140934
142189
|
const url = `${base2}/query/report/YouTube/channel-kpi?${qs}`;
|
|
140935
142190
|
try {
|
|
140936
|
-
const payload = await apiFetch2(url, opts.config, {
|
|
142191
|
+
const payload = await apiFetch2(url, opts.config, {}, opts.verbose);
|
|
140937
142192
|
const headers = Array.isArray(payload.columnHeaders) ? payload.columnHeaders : [];
|
|
140938
142193
|
const first = Array.isArray(payload.rows) && Array.isArray(payload.rows[0]) ? payload.rows[0] : [];
|
|
140939
142194
|
return {
|
|
@@ -140969,7 +142224,7 @@ function parseIsoDate(iso) {
|
|
|
140969
142224
|
function pad(n) {
|
|
140970
142225
|
return String(n).padStart(2, "0");
|
|
140971
142226
|
}
|
|
140972
|
-
function
|
|
142227
|
+
function isoDate2(y, m, d) {
|
|
140973
142228
|
return `${y}-${pad(m)}-${pad(d)}`;
|
|
140974
142229
|
}
|
|
140975
142230
|
function lastDayOfMonth2(y, m) {
|
|
@@ -140982,8 +142237,8 @@ function listMonths(start, end) {
|
|
|
140982
142237
|
let y = s.y;
|
|
140983
142238
|
let m = s.m;
|
|
140984
142239
|
while (y < e.y || y === e.y && m <= e.m) {
|
|
140985
|
-
const monthStart = y === s.y && m === s.m ? start :
|
|
140986
|
-
const monthEnd = y === e.y && m === e.m ? end :
|
|
142240
|
+
const monthStart = y === s.y && m === s.m ? start : isoDate2(y, m, 1);
|
|
142241
|
+
const monthEnd = y === e.y && m === e.m ? end : isoDate2(y, m, lastDayOfMonth2(y, m));
|
|
140987
142242
|
months.push({
|
|
140988
142243
|
start: monthStart,
|
|
140989
142244
|
end: monthEnd,
|
|
@@ -141024,8 +142279,8 @@ function previousCalendarQuarter(start, end) {
|
|
|
141024
142279
|
const endM = prevEndMonth < 1 ? 12 : prevEndMonth;
|
|
141025
142280
|
const startM = endM - 2;
|
|
141026
142281
|
return {
|
|
141027
|
-
start:
|
|
141028
|
-
end:
|
|
142282
|
+
start: isoDate2(year, startM, 1),
|
|
142283
|
+
end: isoDate2(year, endM, lastDayOfMonth2(year, endM))
|
|
141029
142284
|
};
|
|
141030
142285
|
}
|
|
141031
142286
|
function yearOverYearRange(start, end) {
|
|
@@ -141039,11 +142294,11 @@ function yearOverYearRange(start, end) {
|
|
|
141039
142294
|
function shiftYear(p, delta) {
|
|
141040
142295
|
const y = p.y + delta;
|
|
141041
142296
|
const last = lastDayOfMonth2(y, p.m);
|
|
141042
|
-
return
|
|
142297
|
+
return isoDate2(y, p.m, Math.min(p.d, last));
|
|
141043
142298
|
}
|
|
141044
142299
|
function utcToIso(ms) {
|
|
141045
142300
|
const d = new Date(ms);
|
|
141046
|
-
return
|
|
142301
|
+
return isoDate2(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
|
|
141047
142302
|
}
|
|
141048
142303
|
function reportPeriodChrome(current, previous, lang = "zh") {
|
|
141049
142304
|
const kind = classifyReportPeriod(current, previous, lang);
|
|
@@ -141080,8 +142335,8 @@ function lastCompleteQuarter(now = /* @__PURE__ */ new Date()) {
|
|
|
141080
142335
|
const qStartMonth = qEndMonth - 2;
|
|
141081
142336
|
const year = m <= 3 ? y - 1 : y;
|
|
141082
142337
|
return {
|
|
141083
|
-
start:
|
|
141084
|
-
end:
|
|
142338
|
+
start: isoDate2(year, qStartMonth, 1),
|
|
142339
|
+
end: isoDate2(year, qEndMonth, lastDayOfMonth2(year, qEndMonth))
|
|
141085
142340
|
};
|
|
141086
142341
|
}
|
|
141087
142342
|
|
|
@@ -141962,9 +143217,10 @@ async function runGoogleQuarterlyRender(opts) {
|
|
|
141962
143217
|
readMetaRange(merged, "previous"),
|
|
141963
143218
|
lang
|
|
141964
143219
|
);
|
|
143220
|
+
const reportPayload = { ...merged, periodChrome };
|
|
141965
143221
|
const outHtml = injectQuarterlyReport(
|
|
141966
143222
|
localizeReportHtml(html, lang),
|
|
141967
|
-
stampMetaLang(
|
|
143223
|
+
stampMetaLang(reportPayload, lang)
|
|
141968
143224
|
);
|
|
141969
143225
|
if (!outHtml.includes("homeCDN/echarts.min.js") || /new Chart\s*\(/.test(outHtml)) {
|
|
141970
143226
|
console.error("\n\u274C \u6A21\u677F\u5FC5\u987B\u4F7F\u7528 ECharts\uFF0C\u7981\u6B62 Chart.js\u3002\n");
|
|
@@ -143856,7 +145112,7 @@ function sumActionArray(raw) {
|
|
|
143856
145112
|
}
|
|
143857
145113
|
|
|
143858
145114
|
// src/commands/facebook-analysis/entities.ts
|
|
143859
|
-
function
|
|
145115
|
+
function fail4(label2, err) {
|
|
143860
145116
|
const msg = err instanceof Error ? err.message : String(err);
|
|
143861
145117
|
console.error(`
|
|
143862
145118
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -143884,7 +145140,7 @@ async function runFacebookAccountStatus(opts) {
|
|
|
143884
145140
|
try {
|
|
143885
145141
|
row = await fetchFacebookAccount(config, manifestId, !!opts.verbose);
|
|
143886
145142
|
} catch (err) {
|
|
143887
|
-
|
|
145143
|
+
fail4("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
|
|
143888
145144
|
}
|
|
143889
145145
|
const payload = { account: manifestId, ...row };
|
|
143890
145146
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
@@ -143934,7 +145190,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
143934
145190
|
try {
|
|
143935
145191
|
effectiveStatus = parseEffectiveStatusFilter(opts.effectiveStatus);
|
|
143936
145192
|
} catch (err) {
|
|
143937
|
-
|
|
145193
|
+
fail4("\u53C2\u6570\u9519\u8BEF", err);
|
|
143938
145194
|
}
|
|
143939
145195
|
const pageSize = resolveFacebookPageSize(opts.pageSize);
|
|
143940
145196
|
const config = loadConfig(opts.token);
|
|
@@ -143959,7 +145215,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
143959
145215
|
adsetId: opts.adsetId?.trim() || void 0
|
|
143960
145216
|
});
|
|
143961
145217
|
} catch (err) {
|
|
143962
|
-
|
|
145218
|
+
fail4(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
|
|
143963
145219
|
}
|
|
143964
145220
|
const payload = wrapListJson({
|
|
143965
145221
|
page: 1,
|
|
@@ -144080,7 +145336,7 @@ async function runFacebookInsights(opts) {
|
|
|
144080
145336
|
breakdown = resolveFacebookBreakdown(opts.breakdown);
|
|
144081
145337
|
timeIncrement = parseOptionalNumber2(opts.timeIncrement);
|
|
144082
145338
|
} catch (err) {
|
|
144083
|
-
|
|
145339
|
+
fail4("\u53C2\u6570\u9519\u8BEF", err);
|
|
144084
145340
|
}
|
|
144085
145341
|
const config = loadConfig(opts.token);
|
|
144086
145342
|
let items3;
|
|
@@ -144096,7 +145352,7 @@ async function runFacebookInsights(opts) {
|
|
|
144096
145352
|
adIds: opts.adIds?.trim() || void 0
|
|
144097
145353
|
});
|
|
144098
145354
|
} catch (err) {
|
|
144099
|
-
|
|
145355
|
+
fail4("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
|
|
144100
145356
|
}
|
|
144101
145357
|
const payload = {
|
|
144102
145358
|
account: manifestId,
|
|
@@ -146925,7 +148181,7 @@ async function fetchOfficialReport(config, opts) {
|
|
|
146925
148181
|
}
|
|
146926
148182
|
|
|
146927
148183
|
// src/commands/tiktok-analysis/entities.ts
|
|
146928
|
-
function
|
|
148184
|
+
function fail5(label2, err) {
|
|
146929
148185
|
const msg = err instanceof Error ? err.message : String(err);
|
|
146930
148186
|
console.error(`
|
|
146931
148187
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -146939,7 +148195,7 @@ async function runTikTokAccountStatus(opts) {
|
|
|
146939
148195
|
try {
|
|
146940
148196
|
rows = await fetchAdvertiserInfoList(config, id, !!opts.verbose);
|
|
146941
148197
|
} catch (err) {
|
|
146942
|
-
|
|
148198
|
+
fail5("\u67E5\u8BE2 TikTok \u8D26\u6237\u4FE1\u606F\u5931\u8D25\uFF08\u987B\u62E5\u6709\u8BE5\u5E7F\u544A\u4E3B\uFF0C\u5217\u8868\u53EF\u89C1\u4E0D\u591F\uFF09", err);
|
|
146943
148199
|
}
|
|
146944
148200
|
const payload = wrapListJson({
|
|
146945
148201
|
page: 1,
|
|
@@ -146994,7 +148250,7 @@ async function runTikTokCampaignEntities(opts) {
|
|
|
146994
148250
|
verbose: !!opts.verbose
|
|
146995
148251
|
});
|
|
146996
148252
|
} catch (err) {
|
|
146997
|
-
|
|
148253
|
+
fail5("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
|
|
146998
148254
|
}
|
|
146999
148255
|
const payload = wrapListJson({
|
|
147000
148256
|
page: 1,
|
|
@@ -147056,7 +148312,7 @@ async function runTikTokAdGroupEntities(opts) {
|
|
|
147056
148312
|
verbose: !!opts.verbose
|
|
147057
148313
|
});
|
|
147058
148314
|
} catch (err) {
|
|
147059
|
-
|
|
148315
|
+
fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
|
|
147060
148316
|
}
|
|
147061
148317
|
const payload = wrapListJson({
|
|
147062
148318
|
page: 1,
|
|
@@ -147123,7 +148379,7 @@ async function runTikTokAdEntities(opts) {
|
|
|
147123
148379
|
verbose: !!opts.verbose
|
|
147124
148380
|
});
|
|
147125
148381
|
} catch (err) {
|
|
147126
|
-
|
|
148382
|
+
fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
|
|
147127
148383
|
}
|
|
147128
148384
|
const payload = wrapListJson({
|
|
147129
148385
|
page: 1,
|
|
@@ -147197,7 +148453,7 @@ async function runTikTokOfficialReport(opts) {
|
|
|
147197
148453
|
verbose: !!opts.verbose
|
|
147198
148454
|
});
|
|
147199
148455
|
} catch (err) {
|
|
147200
|
-
|
|
148456
|
+
fail5("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
|
|
147201
148457
|
}
|
|
147202
148458
|
const totals = summarizeTikTokOfficialReport(result.items);
|
|
147203
148459
|
const payload = {
|
|
@@ -148512,7 +149768,7 @@ function asRecord42(raw) {
|
|
|
148512
149768
|
}
|
|
148513
149769
|
|
|
148514
149770
|
// src/commands/yandex-analysis/entities.ts
|
|
148515
|
-
function
|
|
149771
|
+
function fail6(label2, err) {
|
|
148516
149772
|
const msg = err instanceof Error ? err.message : String(err);
|
|
148517
149773
|
console.error(`
|
|
148518
149774
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -148584,7 +149840,7 @@ async function runYandexAccountStatus(opts) {
|
|
|
148584
149840
|
try {
|
|
148585
149841
|
result = await fetchPath(opts, "overview", {});
|
|
148586
149842
|
} catch (err) {
|
|
148587
|
-
|
|
149843
|
+
fail6("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
|
|
148588
149844
|
}
|
|
148589
149845
|
const row = asRecord42(result.raw);
|
|
148590
149846
|
await emitOrTable(opts, {
|
|
@@ -148626,7 +149882,7 @@ async function runYandexCampaignEntities(opts) {
|
|
|
148626
149882
|
network: flags.network
|
|
148627
149883
|
});
|
|
148628
149884
|
} catch (err) {
|
|
148629
|
-
|
|
149885
|
+
fail6("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
|
|
148630
149886
|
}
|
|
148631
149887
|
const items3 = unwrapYandexItems(result.raw);
|
|
148632
149888
|
await emitOrTable(opts, {
|
|
@@ -148672,7 +149928,7 @@ async function runYandexAdGroupEntities(opts) {
|
|
|
148672
149928
|
campaignId: flags.campaignId
|
|
148673
149929
|
});
|
|
148674
149930
|
} catch (err) {
|
|
148675
|
-
|
|
149931
|
+
fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
|
|
148676
149932
|
}
|
|
148677
149933
|
const items3 = unwrapYandexItems(result.raw);
|
|
148678
149934
|
await emitOrTable(opts, {
|
|
@@ -148722,7 +149978,7 @@ async function runYandexAdEntities(opts) {
|
|
|
148722
149978
|
adGroupId: flags.adGroupId
|
|
148723
149979
|
});
|
|
148724
149980
|
} catch (err) {
|
|
148725
|
-
|
|
149981
|
+
fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
|
|
148726
149982
|
}
|
|
148727
149983
|
const items3 = unwrapYandexItems(result.raw);
|
|
148728
149984
|
const filtered = flags.status != null;
|
|
@@ -148774,7 +150030,7 @@ async function runYandexInsights(opts) {
|
|
|
148774
150030
|
adGroupId: flags.adGroupId
|
|
148775
150031
|
});
|
|
148776
150032
|
} catch (err) {
|
|
148777
|
-
|
|
150033
|
+
fail6("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
|
|
148778
150034
|
}
|
|
148779
150035
|
const items3 = unwrapYandexItems(result.raw);
|
|
148780
150036
|
await emitOrTable(opts, {
|