AdsApp.​ExperimentSelector

Fetches experiments. Supports filtering and sorting.

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();
}
Related:

Methods:

MemberTypeDescription
get AdsApp.ExperimentIterator Fetches the requested experiments and returns an iterator.
orderBy AdsApp.ExperimentSelector Specifies the ordering of the resulting entities.
withCondition AdsApp.ExperimentSelector Adds the specified condition to the selector in order to narrow down the results.
withIds AdsApp.ExperimentSelector Restricts this selector to return only experiments with the given experiment IDs.
withLimit AdsApp.ExperimentSelector Specifies limit for the selector to use.
withResourceNames 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:

TypeDescription
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:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
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");
All specified conditions are 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 and Long 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 ()
Conditions using 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:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
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']);
will only get the experiment with ID 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:

NameTypeDescription
ids Object[] Array of experiment IDs.

Return values:

TypeDescription
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:

NameTypeDescription
limit int How many entities to return.

Return values:

TypeDescription
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:

NameTypeDescription
resourceNames String[] Array of experiment resource names.

Return values:

TypeDescription
AdsApp.ExperimentSelector The selector restricted to the given resource names.