User Lists
Stay organized with collections
Save and categorize content based on your preferences.
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
;
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThe provided Google Ads scripts demonstrate how to retrieve, examine, and manage user lists within your account.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve all user lists and their member counts (separately for Search and Display campaigns) using these scripts.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts also enable opening a specific user list by name and identifying the search campaigns it targets.\u003c/p\u003e\n"],["\u003cp\u003eIf no user list with the specified name exists, the script throws an error to indicate this.\u003c/p\u003e\n"]]],[],null,["# User Lists\n\nRetrieve all user lists\n-----------------------\n\n```gdscript\nfunction getAllUserLists() {\n const userLists = AdsApp.userlists().get();\n console.log(`${userLists.totalNumEntities()} user lists found.`);\n return userLists;\n}\n```\n\nLog the number of members in each user list\n-------------------------------------------\n\n```perl6\nfunction logUserListMemberCount() {\n const userlists = AdsApp.userlists().get();\n for (const userlist of userlists) {\n console.log(`${userlist.getName()} has ${userlist.getSizeForSearch()} `\n + `members for Search campaigns and ${userlist.getSizeForDisplay()} `\n + `members for Display campaigns.`);\n }\n}\n```\n\nOpen a user list\n----------------\n\n```gdscript\nfunction openUserList(name) {\n const userlists = AdsApp.userlists()\n .withCondition(`user_list.name = '${name}'`)\n .get();\n if (userlists.totalNumEntities() == 0) {\n throw new Error(`No user list with name '${name}' found.`);\n }\n const userlist = userlists.next();\n userlist.open();\n}\n```\n\nRetrieve search campaigns targeted by a user list\n-------------------------------------------------\n\n```gdscript\nfunction getSearchCampaignsTargetedByUserList(name) {\n const userlists = AdsApp.userlists()\n .withCondition(`user_list.name = '${name}'`)\n .get();\n if (userlists.totalNumEntities() == 0) {\n throw new Error(`No user list with name '${name}' found.`);\n }\n const userlist = userlists.next();\n const campaigns = userlist.targetedCampaigns().get();\n console.log(`Userlist '${name}' is targeting ${campaigns.totalNumEntities()} campaigns.`);\n return campaigns;\n}\n```"]]