Fetches labels. Supports filtering and sorting.
Typical usage:
var labelSelector = AdsApp.labels()
.withCondition("CampaignsCount > 5")
.orderBy("CampaignsCount DESC");
var labelIterator = labelSelector.get();
while (labelIterator.hasNext()) {
var label = labelIterator.next();
}
Related:
Methods:
get()
Fetches the requested labels and returns an iterator.
Return values:
orderBy(orderBy)
Specifies the ordering of the resulting entities.
orderBy
parameter can have one of the
following forms:
orderBy("Name")
- orders results by Name, in ascending order.
orderBy("CampaignsCount ASC")
- orders results by the number of Campaigns this
label is applied to, in ascending order.
orderBy("AdGroupsCount DESC")
- orders results by the number of Ad Groups this
label is applied to, in descending order.
See LabelSelector.withCondition(String) for enumeration of columns that can be used.
orderBy()
may be called multiple times. Consider the following example:
selector = selector.orderBy("CampaignsCount DESC").orderBy("Name");
The results will be ordered by CampaignsCount in descending order. Results with equal
CampaignsCount value will be ordered by Name in ascending order.
Arguments:
Name | Type | Description |
orderBy |
String |
Ordering to apply. |
Return values:
withCondition(condition)
Adds the specified condition to the selector in order to narrow down the results.
Multiple conditions may be added to the same selector:
selector = selector
.withCondition("CampaignsCount > 5")
.withCondition("KeywordsCount > 100");
All specified conditions are
AND
-ed together. The above example will retrieve labels
that have over 5 campaigns and over 100 keywords associated with them.
The parameter to be passed into this method must be of the following form:
"COLUMN_NAME OPERATOR VALUE"
Operators
The operator that can be used in a condition depends on the type of column.
- For
Long
columns (e.g. CampaignsCount):
< <= > >= = !=
- For
String
columns (e.g. Name):
= != STARTS_WITH STARTS_WITH_IGNORE_CASE
CONTAINS CONTAINS_IGNORE_CASE DOES_NOT_CONTAIN DOES_NOT_CONTAIN_IGNORE_CASE
Operators are case-sensitive:
starts_with
won't work.
Columns
All column names are case-sensitive.
Column |
Type |
Example |
Name |
String |
withCondition("Name CONTAINS 'priority'") |
CampaignsCount |
Long |
withCondition("CampaignsCount = 2") |
AdGroupsCount |
Long |
withCondition("AdGroupsCount > 10") |
AdsCount |
Long |
withCondition("AdsCount != 0") |
KeywordsCount |
Long |
withCondition("KeywordsCount < 30") |
Arguments:
Name | Type | Description |
condition |
String |
Condition to add to the selector. |
Return values:
withIds(ids)
Restricts this selector to return only labels with the given
label IDs.
var labelIds = [12345, 23456, 34567];
selector = selector.withIds(labelIds);
The resulting selector can be further refined by applying additional conditions to it. The
ID-based condition will then be AND-ed together with all the other conditions, including any
other ID-based conditions. So, for instance, the following selector:
AdsApp.labels()
.withIds([12345, 23456, 34567])
.withIds([34567, 45678, 56789]);
will only get the label with ID
34567
, since it would be the only
label that satisfies both ID conditions.
The selector can only support up to 10,000 IDs. If more than 10,000 IDs are specified, the
corresponding get() call will fail with a runtime error.
Arguments:
Name | Type | Description |
ids |
long[] |
Array of label IDs. |
Return values:
withLimit(limit)
Specifies limit for the selector to use. For instance,
withLimit(50)
returns only the
first 50 entities.
Arguments:
Name | Type | Description |
limit |
int |
How many entities to return. |
Return values: