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:
get()
Fetches the requested experiments 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("campaign_experiment.name")
- orders results by Name, in ascending order.
orderBy("campaign_experiment.base_campaign ASC")
- orders results by base
campaign id, in ascending order.
orderBy("campaign_experiment.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("campaign_experiment.base_campaign ASC")
.orderBy("campaign_experiment.name");
The results will be ordered by campaign_experiment.base_campaign in ascending order. Results
with equal campaign_experiment.base_campaign values will be ordered by campaign_experiment.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("campaign_experiment.id = 123456789")
.withCondition("campaign_experiment.status = ACTIVE");
All specified conditions are
AND
-ed together. The above example will retrieve
experiments with 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. campaign_experiment.id):
< <= > >= = !=
- For
String
columns (e.g. campaign_experiment.name):
= != (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
- For
Enumeration
columns (ones that can only take one value from a predefined
list, such as campaign_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 |
campaign_experiment.name |
String |
withCondition("campaign_experiment.name CONTAINS 'experiment_'") |
campaign_experiment.start_date |
String |
withCondition("campaign_experiment.start_date = '2017-08-15'") |
campaign_experiment.end_date |
String |
withCondition("campaign_experiment.end_date = '2017-08-15'") |
campaign_experiment.status |
Enumeration: INITIALIZING , ENABLED , APPLYING , APPLIED ,
REMOVED , INITIALIZING_FAILED , PROMOTION_FAILED ,
GRADUATED , FINISHED |
withCondition("campaign_experiment.status = ACTIVE") |
campaign_draft.base_campaign |
String |
withCondition("campaign_draft.base_campaign =
'customers/1234567890/campaigns/123'") . The value is a campaign resource name. |
campaign_experiment.id |
Long |
withCondition("campaign_experiment.id = 123456789") |
campaign_experiment.campaign_draft |
String |
withCondition("campaign_experiment.campaign_draft =
'customers/1234567890/campaigns/123'") . The value is a campaign resource name. |
campaign_experiment.traffic_split_percent |
Integer |
withCondition("campaign_experiment.traffic_split_percent > 50") |
Arguments:
Name | Type | Description |
condition |
String |
Condition to add to the selector. |
Return values:
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:
Name | Type | Description |
ids |
Object[] |
Array of experiment 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:
withResourceNames(resourceNames)
Restricts this selector to return only experiments with the given Google Ads
API resource names.
const experimentResourceNames = [
'customers/1234567890/campaignExperiments/111',
'customers/1234567890/campaignExperiments/222',
'customers/1234567890/campaignExperiments/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: