广告系列
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
获取所有广告系列
function getAllCampaigns() {
// AdsApp.campaigns() will return all campaigns that are not removed by
// default.
const campaignIterator = AdsApp.campaigns().get();
console.log(`Total campaigns found : ${campaignIterator.totalNumEntities()}`);
return campaignIterator;
}
按名称获取广告系列
function getCampaignByName(name) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${name}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
console.log(`Campaign Name: ${campaign.getName()}`);
console.log(`Enabled: ${campaign.isEnabled()}`);
console.log(`Bidding strategy: ${campaign.getBiddingStrategyType()}`);
console.log(`Ad rotation: ${campaign.getAdRotationType()}`);
console.log(`Start date: ${formatDate(campaign.getStartDate())}`);
console.log(`End date: ${formatDate(campaign.getEndDate())}`);
return campaign;
} else {
throw new Error(`No campaign named "${name}" found`);
}
}
function formatDate(date) {
function zeroPad(number) { return Utilities.formatString('%02d', number); }
return (date == null) ? 'None' : zeroPad(date.year) + zeroPad(date.month) +
zeroPad(date.day);
}
获取广告系列的统计信息
function getCampaignStats(name) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${name}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
// You can also request reports for pre-defined date ranges. See
// https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_campaign#getStatsFor_1,
// DateRangeLiteral section for possible values.
const stats = campaign.getStatsFor('LAST_MONTH');
console.log(`${campaign.getName()}: ${stats.getClicks()} clicks, ${stats.getImpressions()} impressions`);
return stats;
} else {
throw new Error(`No campaign named "${name}" found`);
}
}
暂停广告系列
function pauseCampaign(name) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${name}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
campaign.pause();
} else {
throw new Error(`No campaign named "${name}" found`);
}
}
获取广告系列的设备出价调节系数
function getCampaignBidModifiers(name) {
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${name}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
console.log('Campaign name: ' + campaign.getName());
const platforms = {};
for (const platform of campaign.targeting().platforms()) {
console.log(`${platform.getName()} bid modifier: ${platform.getBidModifier()}`);
platforms[platform.getName()] = platform.getBidModifier();
}
return platforms;
} else {
throw new Error(`No campaign named "${name}" found`);
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-12。
[[["易于理解","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"]],["最后更新时间 (UTC):2024-09-12。"],[[["The provided code snippets demonstrate how to interact with Google Ads campaigns programmatically using Google Ads Scripts."],["Functionality includes retrieving all campaigns, getting a specific campaign by name, and accessing campaign statistics."],["You can also pause campaigns and retrieve device bid modifiers for specific campaigns using the provided functions."],["Each function utilizes the `AdsApp.campaigns()` method to access and manipulate campaign data within your Google Ads account."],["Error handling is implemented to ensure smooth execution and inform users when a specified campaign is not found."]]],[]]