קבוצות של מודעות
הוספת קבוצת מודעות
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;
}
עדכון של הצעת המחיר לקליק שמוגדרת כברירת מחדל בקבוצת מודעות
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 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2024-09-12 (שעון UTC).
[null,null,["עדכון אחרון: 2024-09-12 (שעון UTC)."],[[["The code snippets provide functions to manage Google Ads ad groups, including creating, retrieving, updating, and pausing them."],["Functions are included to get ad group statistics, such as clicks and impressions, for specific date ranges."],["You can retrieve all ad groups or filter them by name using dedicated functions."],["The provided examples demonstrate how to adjust an ad group's default CPC bid and access its device bid modifiers."],["Error handling is implemented to inform users when a specified ad group or campaign is not found."]]],[]]