預算
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
設定廣告活動預算
function setCampaignBudget(name, amount) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = '${name}'`)
.get();
if (!campaignIterator.hasNext()) {
throw new Error(`No campaign with name '${name}' found.`);
}
const campaign = campaignIterator.next();
campaign.getBudget().setAmount(amount);
}
擷取廣告活動預算
function getBudgetForCampaign(campaignName) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = '${name}'`)
.get();
if (!campaignIterator.hasNext()) {
throw new Error(`No campaign with name '${name}' found.`);
}
const campaign = campaignIterator.next();
return campaign.getBudget();
}
記錄廣告活動預算詳情
function logBudgetDetails(campaignName) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = '${campaignName}'`)
.get();
if (!campaignIterator.hasNext()) {
throw new Error(`No campaign with name '${campaignName}' found.`);
}
const campaign = campaignIterator.next();
const budget = campaign.getBudget();
console.log(`Budget amount: ${budget.getAmount()}`);
console.log(`Delivery method: ${budget.getDeliveryMethod()}`);
console.log(`Explicitly shared: ${budget.isExplicitlyShared()}`);
// If this is a shared budget, log all the associated campaigns.
// If this is not a shared budget, don't bother since the only associated
// campaign is the one specified by 'campaignName'.
if (budget.isExplicitlyShared()) {
const budgetCampaignIterator = budget.campaigns().get();
console.log(`=======`);
console.log(`Associated campaigns (${budgetCampaignIterator.totalNumEntities()}):`);
for (const associatedCampaign of budgetCampaignIterator) {
console.log(associatedCampaign.getName());
}
}
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThese Google Ads scripts provide functions to set, get, and log details about campaign budgets.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts allow you to find a campaign by name and modify its budget amount.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003elogBudgetDetails\u003c/code\u003e provides detailed information on a campaign's budget, including delivery method, shared status, and associated campaigns if it's a shared budget.\u003c/p\u003e\n"],["\u003cp\u003eError handling is included to identify when a campaign with the specified name cannot be found.\u003c/p\u003e\n"]]],[],null,["# Budgets\n\nSet a campaign budget\n---------------------\n\n```gdscript\nfunction setCampaignBudget(name, amount) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = '${name}'`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name '${name}' found.`);\n }\n const campaign = campaignIterator.next();\n campaign.getBudget().setAmount(amount);\n}\n```\n\nGet campaign budget\n-------------------\n\n```gdscript\nfunction getBudgetForCampaign(campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = '${name}'`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name '${name}' found.`);\n }\n const campaign = campaignIterator.next();\n return campaign.getBudget();\n}\n```\n\nLog campaign budget details\n---------------------------\n\n```gdscript\nfunction logBudgetDetails(campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = '${campaignName}'`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name '${campaignName}' found.`);\n }\n const campaign = campaignIterator.next();\n const budget = campaign.getBudget();\n\n console.log(`Budget amount: ${budget.getAmount()}`);\n console.log(`Delivery method: ${budget.getDeliveryMethod()}`);\n console.log(`Explicitly shared: ${budget.isExplicitlyShared()}`);\n\n // If this is a shared budget, log all the associated campaigns.\n // If this is not a shared budget, don't bother since the only associated\n // campaign is the one specified by 'campaignName'.\n if (budget.isExplicitlyShared()) {\n const budgetCampaignIterator = budget.campaigns().get();\n console.log(`=======`);\n console.log(`Associated campaigns (${budgetCampaignIterator.totalNumEntities()}):`);\n\n for (const associatedCampaign of budgetCampaignIterator) {\n console.log(associatedCampaign.getName());\n }\n }\n}\n```"]]