AI-generated Key Takeaways
-
The provided Google Ads scripts demonstrate how to retrieve, examine, and manage user lists within your account.
-
You can retrieve all user lists and their member counts (separately for Search and Display campaigns) using these scripts.
-
The scripts also enable opening a specific user list by name and identifying the search campaigns it targets.
-
If no user list with the specified name exists, the script throws an error to indicate this.
Retrieve all user lists
function getAllUserLists() { const userLists = AdsApp.userlists().get(); console.log(`${userLists.totalNumEntities()} user lists found.`); return userLists; }
Log the number of members in each user list
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.`); } }
Open a user list
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(); }
Retrieve search campaigns targeted by a user list
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; }