Display
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Tambahkan penempatan ke grup iklan yang sudah ada
function addPlacementToAdGroup(adGroupName, url, cpc) {
const adGroups = AdsApp.adGroups()
.withCondition(`ad_group.name = '${adGroupName}'`)
.get();
if (!adGroups.hasNext()) {
throw new Error(`No ad group with the name '${adGroupName}' was found.`);
}
const adGroup = adGroups.next();
if (adGroups.totalNumEntities() > 1) {
console.warn(`Found ${adGroups.totalNumEntities()} ad groups with the ` +
`name '${adGroupName}'. Adding placement to the ad group in campaign ` +
`'${adGroup.getCampaign().getName()}'.`);
}
// Other display criteria can be built in a similar manner using the
// corresponding builder method in the AdsApp.CampaignDisplay or
// AdsApp.AdGroupDisplay class.
const placementBuilder = adGroup.display()
.newPlacementBuilder()
.withUrl(url); // required
if (cpc) {
placementBuilder.withCpc(cpc); // optional
}
const operation = placementBuilder.build();
if (operation.getStatus() == 'SUCCESS') {
const placement = operation.getResult();
console.log(`Placement with id = ${placement.getId()} and url = ${placement.getUrl()} was created.`);
} else {
console.warn(`Failed to create placement. Errors = ${operation.getErrors().join(', ')}`);
}
}
Ambil semua topik di grup iklan yang sudah ada.
function getAllTopics(campaignName, adGroupName) {
return AdsApp.display()
.topics()
.withCondition(`campaign.name = '${campaignName}'`)
.withCondition(`ad_group.name = '${adGroupName}'`);
}
Catat statistik untuk semua audiens di grup iklan yang ada
function logAudienceStats(campaignName, adGroupName, dateRange = 'LAST_MONTH') {
// Other display criteria can be retrieved in a similar manner using
// the corresponding selector methods in the AdsApp.Display,
// AdsApp.CampaignDisplay or AdsApp.AdGroupDisplay class.
const audienceIterator = AdsApp.display()
.audiences()
.withCondition(`campaign.name = '${campaignName}'`)
.withCondition(`ad_group.name = '${adGroupName}'`)
.get();
console.log('ID, Audience ID, Clicks, Impressions, Cost');
for (const audience of audienceIterator) {
const stats = audience.getStatsFor(dateRange);
// User List IDs (List IDs) are available on the details page of
// a User List (found under the Audiences section of the Shared
// Library)
console.log(`${audience.getId().toFixed(0)}, ${audience.getAudienceId()}, `
+ `${stats.getClicks()}, ${stats.getImpressions()}, ${stats.getCost()}`);
}
}
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-11 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-11 UTC."],[[["The provided code snippets demonstrate how to manage display targeting in Google Ads using scripts."],["It includes functionalities to add placements to ad groups, specifying URLs and optional CPC bids."],["Additionally, it showcases retrieving topics and audience performance statistics within specific ad groups and campaigns."],["Example functions cover topics such as adding placements, retrieving topics by campaign/ad group, and logging audience stats with customizable date ranges."]]],[]]