תקציבים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
הגדרה של תקציב לקמפיין
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());
}
}
}
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-21 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-21 (שעון UTC)."],[[["\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```"]]