گروه های تبلیغاتی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
یک گروه تبلیغاتی اضافه کنید
function addAdGroup(campaignName, adGroupName, defaultCpc = 1.2) {
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();
return campaign.newAdGroupBuilder()
.withName(adGroupName)
.withCpc(defaultCpc)
.build();
}
دریافت همه گروه های تبلیغاتی
function getAllAdGroups() {
// AdsApp.adGroups() will return all ad groups that are not removed by
// default.
const adGroupIterator = AdsApp.adGroups().get();
console.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
return adGroupIterator;
}
یک گروه تبلیغاتی را با نام دریافت کنید
function getAdGroupByName(name) {
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${name}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No ad group with name "${name}" found`);
}
const adGroup = adGroupIterator.next();
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
}
return adGroup;
}
پیشنهاد CPC پیشفرض یک گروه تبلیغاتی را بهروزرسانی کنید
function setAdGroupCpc(name, cpc) {
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${name}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No ad group with name "${name}" found`);
}
const adGroup = adGroupIterator.next();
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
}
adGroup.bidding().setCpc(cpc);
}
آمار یک گروه تبلیغاتی را دریافت کنید
function getAdGroupStats(name, dateRange = 'LAST_MONTH') {
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${name}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No ad group with name "${name}" found`);
}
const adGroup = adGroupIterator.next();
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
}
// You can get stats for a custom date range, or, as in this example, a predefined date range.
// A list of valid predefined date ranges is available at
// https://developers.google.com/google-ads/api/docs/query/date-ranges#predefined_date_range
const stats = adGroup.getStatsFor(dateRange);
console.log(`${adGroup.getName()}, ${stats.getClicks()}, ${stats.getImpressions()}`);
return stats;
}
متوقف کردن یک گروه تبلیغاتی
function pauseAdGroup(name) {
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${name}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No ad group with name "${name}" found`);
}
const adGroup = adGroupIterator.next();
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
}
adGroup.pause();
}
اصلاح کننده های پیشنهاد قیمت دستگاه یک گروه تبلیغاتی را دریافت کنید
function getAdGroupBidModifiers(name) {
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${name}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No ad group with name "${name}" found`);
}
const adGroup = adGroupIterator.next();
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
}
return {
HighEndMobile: adGroup.devices().getMobileBidModifier(),
Tablet: adGroup.devices().getTabletBidModifier(),
Desktop: adGroup.devices().getDesktopBidModifier(),
};
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe code snippets provide functions to manage Google Ads ad groups, including creating, retrieving, updating, and pausing them.\u003c/p\u003e\n"],["\u003cp\u003eFunctions are included to get ad group statistics, such as clicks and impressions, for specific date ranges.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve all ad groups or filter them by name using dedicated functions.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples demonstrate how to adjust an ad group's default CPC bid and access its device bid modifiers.\u003c/p\u003e\n"],["\u003cp\u003eError handling is implemented to inform users when a specified ad group or campaign is not found.\u003c/p\u003e\n"]]],[],null,["# Ad Groups\n\nAdd an ad group\n---------------\n\n```gdscript\nfunction addAdGroup(campaignName, adGroupName, defaultCpc = 1.2) {\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\n const campaign = campaignIterator.next();\n return campaign.newAdGroupBuilder()\n .withName(adGroupName)\n .withCpc(defaultCpc)\n .build();\n}\n```\n\nGet all ad groups\n-----------------\n\n```gdscript\nfunction getAllAdGroups() {\n // AdsApp.adGroups() will return all ad groups that are not removed by\n // default.\n const adGroupIterator = AdsApp.adGroups().get();\n console.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());\n return adGroupIterator;\n}\n```\n\nGet an ad group by name\n-----------------------\n\n```gdscript\nfunction getAdGroupByName(name) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${name}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group with name \"${name}\" found`);\n }\n\n const adGroup = adGroupIterator.next();\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found.\nUsing the one from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n return adGroup;\n}\n```\n\nUpdate an ad group's default CPC bid\n------------------------------------\n\n```gdscript\nfunction setAdGroupCpc(name, cpc) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${name}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group with name \"${name}\" found`);\n }\n\n const adGroup = adGroupIterator.next();\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found.\nUsing the one from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n adGroup.bidding().setCpc(cpc);\n}\n```\n\nGet an ad group's stats\n-----------------------\n\n```gdscript\nfunction getAdGroupStats(name, dateRange = 'LAST_MONTH') {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${name}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group with name \"${name}\" found`);\n }\n\n const adGroup = adGroupIterator.next();\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found.\nUsing the one from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n // You can get stats for a custom date range, or, as in this example, a predefined date range.\n // A list of valid predefined date ranges is available at\n // https://developers.google.com/google-ads/api/docs/query/date-ranges#predefined_date_range\n const stats = adGroup.getStatsFor(dateRange);\n console.log(`${adGroup.getName()}, ${stats.getClicks()}, ${stats.getImpressions()}`);\n return stats;\n}\n```\n\nPause an ad group\n-----------------\n\n```gdscript\nfunction pauseAdGroup(name) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${name}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group with name \"${name}\" found`);\n }\n\n const adGroup = adGroupIterator.next();\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found.\nUsing the one from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n adGroup.pause();\n}\n```\n\nGet an ad group's device bid modifiers\n--------------------------------------\n\n```gdscript\nfunction getAdGroupBidModifiers(name) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${name}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group with name \"${name}\" found`);\n }\n\n const adGroup = adGroupIterator.next();\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found.\nUsing the one from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n return {\n HighEndMobile: adGroup.devices().getMobileBidModifier(),\n Tablet: adGroup.devices().getTabletBidModifier(),\n Desktop: adGroup.devices().getDesktopBidModifier(),\n };\n}\n```"]]