AI-generated Key Takeaways
-
Fetches labels and supports filtering by label IDs, names, descriptions, or other criteria.
-
Allows sorting the results by label properties like name or ID, either ascending or descending.
-
Provides methods to limit the number of fetched labels and retrieve specific labels using resource names.
-
Returns an iterator (
LabelIterator
) to access the fetched labels.
Typical usage:
var labelSelector = AdsApp.labels() .withCondition("CampaignsCount > 5") .orderBy("CampaignsCount DESC"); var labelIterator = labelSelector.get(); while (labelIterator.hasNext()) { var label = labelIterator.next(); }
Methods:
Member | Type | Description |
---|---|---|
get() | AdsApp.LabelIterator |
Fetches the requested labels and returns an iterator. |
orderBy(orderBy) | AdsApp.LabelSelector |
Specifies the ordering of the resulting entities. |
withCondition(condition) | AdsApp.LabelSelector |
Adds the specified condition to the selector in order to narrow down the results. |
withIds(ids) | AdsApp.LabelSelector |
Restricts this selector to return only labels with the given label IDs. |
withLimit(limit) | AdsApp.LabelSelector |
Specifies limit for the selector to use. |
withResourceNames(resourceNames) | AdsApp.LabelSelector |
Restricts this selector to return only labels with the given Google Ads API resource names. |
get()
Fetches the requested labels and returns an iterator. Return values:
Type | Description |
---|---|
AdsApp.LabelIterator |
Iterator of the requested labels. |
orderBy(orderBy)
Specifies the ordering of the resulting entities. orderBy
parameter can have one of the following forms:
orderBy("label.name")
- orders results by label.name, in ascending order.orderBy("label.name ASC")
- orders results by label.name, in ascending order.orderBy("label.id DESC")
- orders results by label.id, 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("label.name DESC").orderBy("label.id");
The results will be ordered by label.name in descending order. Results with equal label.name value will be ordered by label.id in ascending order.
Arguments:
Name | Type | Description |
---|---|---|
orderBy | String |
Ordering to apply. |
Return values:
Type | Description |
---|---|
AdsApp.LabelSelector |
The selector with ordering applied. |
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("label.name CONTAINS 'test'") .withCondition("label.description CONTAINS 'cool'");
AND
-ed together. The above
example will retrieve labels whose name contains 'test' and whose
description contains 'cool'.
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
String
columns (e.g. label.name):= != (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
Columns
All column names are case-sensitive.
Column | Type | Example |
---|---|---|
label.name | String | withCondition("label.name CONTAINS 'priority'") |
Arguments:
Name | Type | Description |
---|---|---|
condition | String |
Condition to add to the selector. |
Return values:
Type | Description |
---|---|
AdsApp.LabelSelector |
The selector with the condition applied. |
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']);
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 | Object[] |
Array of label IDs. |
Return values:
Type | Description |
---|---|
AdsApp.LabelSelector |
The selector restricted to the given IDs. |
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:
Type | Description |
---|---|
AdsApp.LabelSelector |
The selector with limit applied. |
withResourceNames(resourceNames)
Restricts this selector to return only labels with the
given Google Ads API resource names.
const labelResourceNames = [ 'customers/1234567890/labels/111', 'customers/1234567890/labels/222', 'customers/1234567890/labels/333', ]; selector = selector.withResourceNames(labelResourceNames);
The resulting selector can be further refined by applying additional conditions to it. The resource name condition will then be AND-ed together with all the other conditions.
The selector can only support up to 10,000 resource names. If more than 10,000 resource names are specified, the corresponding get() call will fail with a runtime error.
Arguments:
Name | Type | Description |
---|---|---|
resourceNames | String[] |
Array of label resource names. |
Return values:
Type | Description |
---|---|
AdsApp.LabelSelector |
The selector restricted to the given resource names. |