擷取所有的使用者名單
function getAllUserLists() {
const userLists = AdsApp.userlists().get();
console.log(`${userLists.totalNumEntities()} user lists found.`);
return userLists;
}
記錄每份使用者名單中的成員人數
function logUserListMemberCount() {
const userlists = AdsApp.userlists().get();
for (const userlist of userlists) {
console.log(`${userlist.getName()} has ${userlist.getSizeForSearch()} `
+ `members for Search campaigns and ${userlist.getSizeForDisplay()} `
+ `members for Display campaigns.`);
}
}
開啟使用者名單
function openUserList(name) {
const userlists = AdsApp.userlists()
.withCondition(`user_list.name = '${name}'`)
.get();
if (userlists.totalNumEntities() == 0) {
throw new Error(`No user list with name '${name}' found.`);
}
const userlist = userlists.next();
userlist.open();
}
擷取使用者名單指定的搜尋廣告活動
function getSearchCampaignsTargetedByUserList(name) {
const userlists = AdsApp.userlists()
.withCondition(`user_list.name = '${name}'`)
.get();
if (userlists.totalNumEntities() == 0) {
throw new Error(`No user list with name '${name}' found.`);
}
const userlist = userlists.next();
const campaigns = userlist.targetedCampaigns().get();
console.log(`Userlist '${name}' is targeting ${campaigns.totalNumEntities()} campaigns.`);
return campaigns;
}