실험 만들기

실험은 기본 캠페인과 관련된 실험 캠페인을 관리하는 인터페이스입니다. 실험 캠페인은 광고를 게재하고 클릭수, 비용 및 기타 측정항목을 축적할 수 있는 완전한 캠페인입니다.

Google Ads API를 사용하여 실험을 실행하려면 먼저 Experiment를 만들어야 합니다. 이 리소스는 이름 및 실험 유형과 같이 실행할 실험에 대한 주요 정보를 정의합니다. 이 단계에서는 실험과 관련된 어떤 캠페인도 지정하지 않습니다.

다음은 Experiment의 몇 가지 주요 필드에 관한 개요입니다.

  • name: 각 실험의 이름은 고유해야 합니다.
  • description: 나중에 참조하는 데 사용할 수 있는 선택적 필드입니다. 실험 실행 방식에는 영향을 미치지 않습니다.
  • suffix: 접미사가 전체 실험 대상 캠페인의 이름 끝에 추가되어 통제 캠페인과 구분할 수 있습니다. 이러한 개념은 실험 부문 페이지에서 자세히 설명합니다.
  • type: 실행할 실험의 유형입니다. 여기에는 많은 유형이 있지만 대부분은 시스템 실험입니다. 맞춤 실험의 경우 SEARCH_CUSTOM 또는 DISPLAY_CUSTOM를 지정하는 것이 좋습니다.
  • status: 실험을 만들 때 이 필드를 SETUP로 설정합니다. 나중에 실험을 시작하면 이 필드를 통해 현재 진행 중인 작업을 확인할 수 있습니다.
  • start_dateend_date: 실험을 시작하고 종료할 시기를 지정합니다.
  • sync_enabled: 기본적으로 사용 중지됩니다. true로 설정하면 실험이 실행되는 동안 기존 캠페인에 적용된 변경사항이 자동으로 실험 캠페인에 복사됩니다. 자세히 알아보기

다음은 실험을 만드는 예입니다.

Java

private String createExperimentResource(GoogleAdsClient googleAdsClient, long customerId) {
  ExperimentOperation operation =
      ExperimentOperation.newBuilder()
          .setCreate(
              Experiment.newBuilder()
                  // Name must be unique.
                  .setName("Example Experiment #" + getPrintableDateTime())
                  .setType(ExperimentType.SEARCH_CUSTOM)
                  .setSuffix("[experiment]")
                  .setStatus(ExperimentStatus.SETUP)
                  .build())
          .build();

  try (ExperimentServiceClient experimentServiceClient =
      googleAdsClient.getLatestVersion().createExperimentServiceClient()) {
    MutateExperimentsResponse response =
        experimentServiceClient.mutateExperiments(
            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;
  }
}
      

C#

/// <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(
        Services.V16.ExperimentService);

    // 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 " +
        $"'{experimentResourceName}'.");
    return experimentResourceName;
}

      

2,399필리핀

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(
        MutateExperimentsRequest::build($customerId, [$experimentOperation])
    );
    $experimentResourceName = $response->getResults()[0]->getResourceName();
    print "Created experiment with resource name '$experimentResourceName'" . PHP_EOL;

    return $experimentResourceName;
}
      

Python

def create_experiment_resource(client, customer_id):
    """Creates a new experiment resource.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.

    Returns:
        the resource name for the new experiment.
    """
    experiment_operation = client.get_type("ExperimentOperation")
    experiment = experiment_operation.create

    experiment.name = 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]
    )

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

    return experiment_resource_name
      

Ruby

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

  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}."

  experiment
end
      

Perl

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

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

  my $operation =
    Google::Ads::GoogleAds::V16::Services::ExperimentService::ExperimentOperation
    ->new({
      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;
}