搜尋目標對象
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在廣告群組中加入搜尋目標對象
function addSearchAudienceToAdGroup(adGroupName, audienceId, bidModifier = 1.5) {
// Retrieve the ad group.
const adGroups = AdsApp.adGroups()
.withCondition(`ad_group.name = "${adGroupName}"`)
.get();
if (!adGroups.hasNext()) {
throw new Error(`Cannot find ad group with name "${adGroupName}"`);
}
const adGroup = adGroups.next();
if (adGroups.totalNumEntities() > 1) {
console.warn(`More than one ad group with name "${adGroupName}" was ` +
`found. Using the ad group in campaign ` +
`"${adGroup.getCampaign().getName()}"`);
}
// Create the search audience.
const operation = adGroup.targeting()
.newUserListBuilder()
.withAudienceId(audienceId)
.withBidModifier(bidModifier)
.build();
if (!operation.isSuccessful()) {
console.warn(`Failed to attach search audience. ` +
`Errors: ${operation.getErrors().join(', ')}'`);
}
const searchAudience = operation.getResult();
// Display the results.
console.log(`Search audience with name ${searchAudience.getName()} and ` +
`ID = ${searchAudience.getId().toFixed(0)} was added to ` +
`ad group "${adGroupName}".`);
}
按名稱取得廣告群組搜尋目標對象
function getAdGroupSearchAudienceByName(campaignName, adGroupName, audienceName) {
// Retrieve the search audience.
const searchAudiences = AdsApp.adGroupTargeting().audiences()
.withCondition(`campaign.name = "${campaignName}"`)
.withCondition(`ad_group.name = "${adGroupName}"`)
.get();
for (const audience of searchAudiences) {
if (audience.getName() == audienceName) {
return audience;
}
}
// Display the results.
console.warn(`Cannot find an audience "${audienceName}" in the ad group
"${adGroupName}" belonging to the campaign "${campaignName}".`);
}
按統計資料篩選廣告群組搜尋目標對象
function filterAdGroupAudienceByStats() {
// Retrieve top performing search audiences.
const topPerformingAudiences = AdsApp.adGrouptargeting().audiences()
.withCondition(`campaign.name = "Campaign #1"`)
.withCondition(`ad_group.name = "Ad Group #1"`)
.withCondition("metrics.clicks > 34")
.forDateRange("LAST_MONTH")
.get();
for (const audience of topPerformingAudiences) {
const stats = audience.getStatsFor("LAST_MONTH");
console.log(`Search audience with ID = ${audience.getId().toFixed(0)}, ` +
`name = "${audience.getName()}" and audience list ID = ` +
`${audience.getAudienceId()} had ${stats.getClicks()} clicks last ` +
`month.`);
}
}
從廣告活動中排除搜尋目標對象
function addExcludedAudienceToCampaign(campaignName, audienceId) {
// Retrieve the campaign.
const campaigns = AdsApp.campaigns()
.withCondition(`campaign.name = "${campaignName}"`)
.get();
if (!campaigns.hasNext()) {
throw new Error(`Cannot find campaign with name "${campaignName}"`);
}
const campaign = campaigns.next();
// Create the excluded audience.
const operation = campaign.targeting()
.newUserListBuilder()
.withAudienceId(`${audienceId}``)
.exclude();
if (!operation.isSuccessful()) {
console.warn(`Failed to exclude audience ${audienceId}. Errors: ${operation.getErrors().join(', ')}`);
}
const audience = operation.getResult();
console.log(`Excluded audience "${audience.getName()}" from campaign ` +
``"${campaignName}".`);
}
取得廣告活動的排除搜尋目標對象
function getExcludedAudiencesForCampaign(campaignName) {
// Retrieve the campaign.
const campaign = AdsApp.campaigns()
.withCondition(`campaign.name = "${campaignName}"`)
.get();
if (!campaigns.hasNext()) {
throw new Error(`Cannot find campaign with name "${campaignName}"`);
}
const campaign = campaigns.next();
return campaign.targeting().excludedAudiences().get();
}
選擇廣告群組指定目標設定
function setAdGroupTargetSetting(campaignName, adGroupName, group = "USER_INTEREST_AND_ALL", setting = "TARGET_ALL_TRUE") {
// Retrieve the ad group.
const adGroups = AdsApp.adGroups()
.withCondition(`campaign.name = "${campaignName}"`)
.withCondition(`ad_group.name = "${adGroupName}"`)
.get();
if (!adGroups.hasNext()) {
throw new Error(`Cannot find ad group with name "${adGroupName}" in ` +
`campaign "${campaignName}"`);
}
// Change the target setting.
adGroup.targeting().setTargetingSetting(group, setting);
}
更新目標對象出價調節係數
function updateAudienceBidModifer(campaignName, adGroupName, audienceName, bidModifier = 1.5) {
// Create the search audience.
const audiences = AdsApp.adGrouptargeting().audiences()
.withCondition(`campaign.name = "${campaignName}"`)
.withCondition(`ad_group.name = "${adGroupName}"`)
.get();
for (const audience of audiences) {
if (audience.getName() == audienceName) {
audience.bidding().setBidModifier(bidModifier);
}
}
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-10 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2024-09-10 (世界標準時間)。"],[[["These Google Ads scripts provide functions to manage search audiences and targeting settings within ad groups and campaigns."],["You can add, retrieve, filter, and exclude search audiences, as well as adjust bid modifiers."],["Scripts enable you to target or exclude specific user lists based on criteria such as audience ID or name."],["Campaign-level targeting settings can be controlled, including the ability to add excluded audiences to an entire campaign."],["Automated audience management is streamlined by using conditional statements, loops, and specific Google Ads API functions."]]],[]]