Create experiments

Experiments are an interface to manage experimental campaigns related to a base campaign. Experiment campaigns are full-fledged campaigns that can serve ads and accrue clicks, cost, and other metrics.

The first step in running an experiment using the Google Ads API is to create an Experiment. This resource defines some key information about the experiment you want to run, such as a name and experiment type. You do not specify any of the campaigns involved in the experiment at this step.

Here's an overview of some key fields for an Experiment:

  • name: Each experiment must have a unique name.
  • description: An optional field that you can use to reference later. Does not affect how the experiment runs.
  • suffix: The suffix will be appended to the end of the names of the treatment campaigns so you can distinguish them from the control campaign. These concepts will be explained further in the experiment arms page.
  • type: What type of experiment to run. There are many types here, but most of them are system experiments. For your custom experiments, you'll want to specify either SEARCH_CUSTOM or DISPLAY_CUSTOM.
  • status: When creating an experiment, set this field to SETUP. Later on, once you begin the experiment, this field will let you check what it's currently doing
  • start_date and end_date: Specify when the experiment should start and end.

Here's an example of creating an experiment:


private String createExperimentResource(GoogleAdsClient googleAdsClient, long customerId) {
  ExperimentOperation operation =
                  // Name must be unique.
                  .setName("Example Experiment #" + getPrintableDateTime())

  try (ExperimentServiceClient experimentServiceClient =
      googleAdsClient.getLatestVersion().createExperimentServiceClient()) {
    MutateExperimentsResponse response =
            Long.toString(customerId), ImmutableList.of(operation));
    String experiment = response.getResults(0).getResourceName();
    System.out.printf("Created experiment with resource name '%s'%n", experiment);
    return experiment;


/// <summary>
/// Creates the experiment.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The customer ID for which the call is made.</param>
/// <returns>The resource name of the newly created experiment.</returns>
private static string CreateAnExperiment(GoogleAdsClient client, long customerId)
    // Get the ExperimentService.
    ExperimentServiceClient experimentService = client.GetService(

    // Creates the experiment.
    Experiment experiment = new Experiment()
        // Name must be unique.
        Name = $"Example Experiment #{ExampleUtilities.GetRandomString()}",
        Type = ExperimentType.SearchCustom,
        Suffix = "[experiment]",
        Status = ExperimentStatus.Setup

    // Creates the operation.
    ExperimentOperation operation = new ExperimentOperation()
        Create = experiment

    // Makes the API call.
    MutateExperimentsResponse response = experimentService.MutateExperiments(
        customerId.ToString(), new[] { operation });

    // Displays the result.
    string experimentResourceName = response.Results.First().ResourceName;

    Console.WriteLine($"Created experiment with resource name " +
    return experimentResourceName;



private static function createExperimentResource(
    ExperimentServiceClient $experimentServiceClient,
    int $customerId
): string {
    // Creates an experiment and its operation.
    $experiment = new Experiment([
        // Name must be unique.
        'name' => 'Example Experiment #' . Helper::getPrintableDatetime(),
        'type' => ExperimentType::SEARCH_CUSTOM,
        'suffix' => '[experiment]',
        'status' => ExperimentStatus::SETUP
    $experimentOperation = new ExperimentOperation(['create' => $experiment]);

    // Issues a request to create the experiment.
    $response = $experimentServiceClient->mutateExperiments(
    $experimentResourceName = $response->getResults()[0]->getResourceName();
    print "Created experiment with resource name '$experimentResourceName'" . PHP_EOL;

    return $experimentResourceName;


def create_experiment_resource(client, customer_id):
    experiment_operation = client.get_type("ExperimentOperation")
    experiment = experiment_operation.create = f"Example Experiment #{uuid.uuid4()}"
    experiment.type = client.enums.ExperimentTypeEnum.SEARCH_CUSTOM
    experiment.suffix = "[experiment]"
    experiment.status = client.enums.ExperimentStatusEnum.SETUP

        experiment_service = client.get_service("ExperimentService")
        response = experiment_service.mutate_experiments(
            customer_id=customer_id, operations=[experiment_operation]
    except GoogleAdsException as ex:
            f'Request with ID "{ex.request_id}" failed with status '
            f'"{ex.error.code().name}" and includes the following errors:'
        for error in ex.failure.errors:
            print(f'\tError with message "{error.message}".')
            if error.location:
                for field_path_element in error.location.field_path_elements:
                    print(f"\t\tOn field: {field_path_element.field_name}")

    experiment_resource_name = response.results[0].resource_name
    print(f"Created experiment with resource name {experiment_resource_name}")

    return experiment_resource_name



def create_experiment_resource(client, customer_id)
  operation = client.operation.create_resource.experiment do |e|
    # Name must be unique. = "Example Experiment #{( * 1000).to_i}"
    e.type = :SEARCH_CUSTOM
    e.suffix = '[experiment]'
    e.status = :SETUP

  response = client.service.experiment.mutate_experiments(
    customer_id: customer_id,
    operations: [operation],

  experiment = response.results.first.resource_name
  puts "Created experiment with resource name #{experiment}."



sub create_experiment_resource {
  my ($api_client, $customer_id) = @_;

  my $experiment = Google::Ads::GoogleAds::V11::Resources::Experiment->new({
    # Name must be unique.
    name   => "Example Experiment #" . uniqid(),
    type   => SEARCH_CUSTOM,
    suffix => "[experiment]",
    status => SETUP

  my $operation =
      create => $experiment

  my $response = $api_client->ExperimentService()->mutate({
      customerId => $customer_id,
      operations => [$operation]});

  my $resource_name = $response->{results}[0]{resourceName};
  printf "Created experiment with resource name '%s'.\n", $resource_name;
  return $resource_name;