Labels
Stay organized with collections
Save and categorize content based on your preferences.
Get all labels from a user's account
function
getAllLabels
()
{
const
labelIterator
=
AdsApp
.
labels
()
.
get
();
console
.
log
(
`
Total
labels
found
:
$
{
labelIterator
.
totalNumEntities
()}
`
);
return
labelIterator
;
}
Get a label by name
function
getLabelByName
(
name
)
{
const
labelIterator
=
AdsApp
.
labels
()
.
withCondition
(
`
label
.
name
=
"${name}"
`
)
.
get
();
if
(
labelIterator
.
hasNext
())
{
const
label
=
labelIterator
.
next
();
console
.
log
(
`
Name
:
$
{
label
.
getName
()}
`
);
console
.
log
(
`
Description
:
$
{
label
.
getDescription
()}
`
);
console
.
log
(
`
Color
:
$
{
label
.
getColor
()}
`
);
console
.
log
(
`
Number
of
campaigns
:
$
{
label
.
campaigns
()
.
get
()
.
totalNumEntities
()}
`
);
console
.
log
(
`
Number
of
ad
groups
:
$
{
label
.
adGroups
()
.
get
()
.
totalNumEntities
()}
`
);
console
.
log
(
`
Number
of
ads
:
$
{
label
.
ads
()
.
get
()
.
totalNumEntities
()}
`
);
console
.
log
(
`
Number
of
keywords
:
$
{
label
.
keywords
()
.
get
()
.
totalNumEntities
()}
`
);
return
label
;
}
return
null
;
}
Apply a label to a campaign
function
applyLabel
(
labelName
,
campaignName
)
{
//
Retrieve
a
campaign
,
and
apply
a
label
to
it
.
Applying
labels
to
other
//
object
types
is
similar
.
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${campaignName}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
campaign
.
applyLabel
(
labelName
);
}
}
Remove a label from a campaign
function
removeLabel
(
labelName
,
campaignName
)
{
//
Removing
labels
from
other
object
types
is
similar
.
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${campaignName}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
campaign
.
removeLabel
(
labelName
);
}
}
Delete a label from the user's account
function
deleteLabel
(
labelName
)
{
const
labelIterator
=
AdsApp
.
labels
()
.
withCondition
(
`
label
.
name
=
"${labelName}"
`
)
.
get
();
if
(
labelIterator
.
hasNext
())
{
const
label
=
labelIterator
.
next
();
label
.
remove
();
}
}
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\u003eThis script provides functions to manage labels in Google Ads, allowing retrieval of all labels or a specific label by name.\u003c/p\u003e\n"],["\u003cp\u003eIt demonstrates how to apply and remove labels from campaigns, with similar functionality for other Google Ads object types.\u003c/p\u003e\n"],["\u003cp\u003eThe script also includes a function to delete a label entirely from the user's Google Ads account.\u003c/p\u003e\n"],["\u003cp\u003eIncluded are example functions that show how to get information like a label's description, color, and the number of entities it's applied to.\u003c/p\u003e\n"]]],[],null,["# Labels\n\nGet all labels from a user's account\n------------------------------------\n\n```gdscript\nfunction getAllLabels() {\n const labelIterator = AdsApp.labels().get();\n console.log(`Total labels found: ${labelIterator.totalNumEntities()}`);\n return labelIterator;\n}\n```\n\nGet a label by name\n-------------------\n\n```gdscript\nfunction getLabelByName(name) {\n const labelIterator = AdsApp.labels()\n .withCondition(`label.name = \"${name}\"`)\n .get();\n if (labelIterator.hasNext()) {\n const label = labelIterator.next();\n console.log(`Name: ${label.getName()}`);\n console.log(`Description: ${label.getDescription()}`);\n console.log(`Color: ${label.getColor()}`);\n console.log(`Number of campaigns: ${label.campaigns().get().totalNumEntities()}`);\n console.log(`Number of ad groups: ${label.adGroups().get().totalNumEntities()}`);\n console.log(`Number of ads: ${label.ads().get().totalNumEntities()}`);\n console.log(`Number of keywords: ${label.keywords().get().totalNumEntities()}`);\n return label;\n }\n return null;\n}\n```\n\nApply a label to a campaign\n---------------------------\n\n```gdscript\nfunction applyLabel(labelName, campaignName) {\n // Retrieve a campaign, and apply a label to it. Applying labels to other\n // object types is similar.\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n campaign.applyLabel(labelName);\n }\n}\n```\n\nRemove a label from a campaign\n------------------------------\n\n```gdscript\nfunction removeLabel(labelName, campaignName) {\n // Removing labels from other object types is similar.\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n campaign.removeLabel(labelName);\n }\n}\n```\n\nDelete a label from the user's account\n--------------------------------------\n\n```gdscript\nfunction deleteLabel(labelName) {\n const labelIterator = AdsApp.labels()\n .withCondition(`label.name = \"${labelName}\"`)\n .get();\n if (labelIterator.hasNext()) {\n const label = labelIterator.next();\n label.remove();\n }\n}\n```"]]