Kampanye
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dapatkan semua kampanye
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;
}
Dapatkan kampanye berdasarkan nama
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);
}
Dapatkan statistik kampanye
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`);
}
}
Jeda kampanye
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`);
}
}
Dapatkan pengubah bid perangkat kampanye
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`);
}
}
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2024-09-12 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2024-09-12 UTC."],[[["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."]]],[]]