This is the legacy documentation for Google Ads scripts. Go to the current docs.

AdsApp.​ExperimentSelector

Fetches experiments. Supports filtering and sorting.

Typical usage:

 var experimentSelector = AdsApp.experiments()
     .withCondition("BaseCampaignId = 123456789")
     .orderBy("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.

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("Name") - orders results by Name, in ascending order.
  • orderBy("BaseCampaignId ASC") - orders results by base campaign id, in ascending order.
  • orderBy("Id DESC") - orders results by id, in descending order.

See ExperimentSelector.withCondition(String) for enumeration of columns that can be used.

orderBy() may be called multiple times. Consider the following example:

 selector = selector.orderBy("BaseCampaignId ASC").orderBy("Name");

The results will be ordered by BaseCampaignId in ascending order. Results with equal BaseCampaignId values will be ordered by Name 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("BaseCampaignId = 123456789")
     .withCondition("Status = ACTIVE");
All specified conditions are AND-ed together. The above example will retrieve experiments with base campaign id 123456789 and status ACTIVE.

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. BaseCampaignId):
    <  <=  >  >=  =  !=
  • For String columns (e.g. Name):
    =  !=  STARTS_WITH  STARTS_WITH_IGNORE_CASE
     CONTAINS  CONTAINS_IGNORE_CASE  DOES_NOT_CONTAIN  DOES_NOT_CONTAIN_IGNORE_CASE
  • For Enumeration columns (ones that can only take one value from a predefined list, such as Status):
     =  !=  IN []  NOT_IN []
Conditions using IN and NOT_IN operators look as follows:
 withCondition("ColumnName IN [Value1, Value2]")
Operators are case-sensitive: starts_with won't work.

Columns

All column names are case-sensitive, and so are all values of enumerated columns (such as Status).

Column Type Example
Name String withCondition("Name CONTAINS 'experiment_'")
StartDate String withCondition("StartDate = '20170815'")
EndDate String withCondition("EndDate = '20170815'")
Status Enumeration: CREATING, ACTIVE, APPLYING, APPLIED, REMOVED, UNABLE_TO_CREATE, UNABLE_TO_APPLY, GRADUATED, FINISHED withCondition("Status = ACTIVE")
BaseCampaignId Long withCondition("BaseCampaignId = 123456789")
ExperimentCampaignId Long withCondition("ExperimentCampaignId = 123456789")
DraftId Long withCondition("DraftId = 123456789")
Id Long withCondition("Id = 123456789")
TrafficSplitPercent Integer withCondition("TrafficSplitPercent > 50")

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 long[] 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.