AI-generated Key Takeaways
-
Fetches experiments and allows for filtering by ID, status, date, and name, or by Google Ads API resource name.
-
Supports ordering results by experiment properties like name, ID, and type.
-
Limits the number of returned experiments using
withLimit()
. -
Provides an iterator (
ExperimentIterator
) to access fetched experiments. -
Uses conditions to narrow down results based on various criteria such as experiment ID or status.
Typical usage:
var experimentSelector = AdsApp.experiments() .withCondition("experiment.experiment_id = 123456789") .orderBy("experiment.name ASC"); var experimentIterator = experimentSelector.get(); while (experimentIterator.hasNext()) { var experiment = experimentIterator.next(); }
Methods:
Member | Type | Description |
---|---|---|
get() | AdsApp.ExperimentIterator |
Fetches the requested experiments and returns an iterator. |
orderBy(orderBy) | AdsApp.ExperimentSelector |
Specifies the ordering of the resulting entities. |
withCondition(condition) | AdsApp.ExperimentSelector |
Adds the specified condition to the selector in order to narrow down the results. |
withIds(ids) | AdsApp.ExperimentSelector |
Restricts this selector to return only experiments with the given experiment IDs. |
withLimit(limit) | AdsApp.ExperimentSelector |
Specifies limit for the selector to use. |
withResourceNames(resourceNames) | AdsApp.ExperimentSelector |
Restricts this selector to return only experiments with the given Google Ads API resource names. |
get()
Fetches the requested experiments and returns an iterator. Return values:
Type | Description |
---|---|
AdsApp.ExperimentIterator |
Iterator of the requested experiments. |
orderBy(orderBy)
Specifies the ordering of the resulting entities. orderBy
parameter can have one of the following forms:
orderBy("experiment.name")
- orders results by Name, in ascending order.orderBy("experiment.experiment_id DESC")
- orders results by id, in descending order.
See ExperimentSelector.withCondition(String) for enumeration of columns that can be used.
orderBy()
can be called multiple times. Consider the
following example:
selector = selector .orderBy("experiment.type ASC") .orderBy("experiment.experiment_id");
The results will be ordered by experiment.type in ascending order.
Results with equal experiment.type
values will be ordered by
experiment.experiment_id
in ascending order.
Arguments:
Name | Type | Description |
---|---|---|
orderBy | String |
Ordering to apply. |
Return values:
Type | Description |
---|---|
AdsApp.ExperimentSelector |
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("experiment.experiment_id = 123456789") .withCondition("experiment.status = ENABLED");
AND
-ed together. The above
example will retrieve experiments with ID 123456789
and
status ENABLED
.
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
Integer
andLong
columns (e.g. experiment.experiment_id):< <= > >= = !=
- For
String
columns (e.g. experiment.name):= != (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
- For
Enumeration
columns (ones that can only take one value from a predefined list, such as experiment.status):= != IN () NOT IN ()
IN
and NOT IN
operators look as
follows:
withCondition("ColumnName IN (Value1, Value2)")
Columns
All column names are case-sensitive, and so are all values of enumerated columns (such as Status).
Column | Type | Example |
---|---|---|
experiment.name | String | withCondition("experiment.name CONTAINS 'experiment_'") |
experiment.start_date | String | withCondition("experiment.start_date = '2017-08-15'") |
experiment.end_date | String | withCondition("experiment.end_date = '2017-08-15'") |
experiment.status |
Enumeration: SETUP , ENABLED ,
PROMOTED , INITIATED , REMOVED ,
GRADUATED , HALTED
|
withCondition("experiment.status = ACTIVE") |
experiment.experiment_id | Long | withCondition("experiment.experiment_id = 123456789") |
Arguments:
Name | Type | Description |
---|---|---|
condition | String |
Condition to add to the selector. |
Return values:
Type | Description |
---|---|
AdsApp.ExperimentSelector |
The selector with the condition applied. |
withIds(ids)
Restricts this selector to return only experiments with the
given
experiment IDs.
var experimentIds = ['12345', '23456', '34567']; selector = selector.withIds(experimentIds);
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.experiments() .withIds(['12345', '23456', '34567']) .withIds(['34567', '45678', '56789']);
34567
, since it
would be the only
experiment 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 experiment IDs. |
Return values:
Type | Description |
---|---|
AdsApp.ExperimentSelector |
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.ExperimentSelector |
The selector with limit applied. |
withResourceNames(resourceNames)
Restricts this selector to return only experiments with the
given Google Ads API resource names.
const experimentResourceNames = [ 'customers/1234567890/experiments/111', 'customers/1234567890/experiments/222', 'customers/1234567890/experiments/333', ]; selector = selector.withResourceNames(experimentResourceNames);
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 experiment resource names. |
Return values:
Type | Description |
---|---|
AdsApp.ExperimentSelector |
The selector restricted to the given resource names. |