// Get AdWordsUser from "~/adwords.properties".
AdWordsUser user = new AdWordsUser();
// Get the ExperimentService.
ExperimentServiceInterface experimentService =
user.getService(AdWordsService.V201306.EXPERIMENT_SERVICE);
// Get the AdGroupService.
AdGroupServiceInterface adGroupService =
user.getService(AdWordsService.V201306.ADGROUP_SERVICE);
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
user.getService(AdWordsService.V201306.ADGROUP_CRITERION_SERVICE);
// Replace with valid values of your account.
long campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
long criterionId = Long.parseLong("INSERT_CRITERION_ID_HERE");
// Create experiment.
Experiment experiment = new Experiment();
experiment.setCampaignId(campaignId);
experiment.setName("Interplanetary Experiment #" + System.currentTimeMillis());
experiment.setQueryPercentage(10);
experiment.setStartDateTime(new SimpleDateFormat("yyyyMMdd HHmmss Z").format(new Date()));
// Create operation.
ExperimentOperation experimentOperation = new ExperimentOperation();
experimentOperation.setOperand(experiment);
experimentOperation.setOperator(Operator.ADD);
// Add experiment.
ExperimentReturnValue result =
experimentService.mutate(new ExperimentOperation[]{experimentOperation});
if (result.getValue() != null) {
for(Experiment experimentResult : result.getValue()) {
System.out.println("Experiment with name \"" + experimentResult.getName()
+ "\" and id \"" + experimentResult.getId() + "\" was added.");