प्रयोग बनाएं

प्रयोग किसी बेस कैंपेन से जुड़े, प्रयोग के तौर पर शुरू किए गए कैंपेन को मैनेज करने के लिए इंटरफ़ेस होते हैं. प्रयोग वाले कैंपेन पूरे कैंपेन होते हैं, जो विज्ञापन दिखा सकते हैं और क्लिक, लागत, और दूसरे मेट्रिक हासिल कर सकते हैं.

Google Ads API का इस्तेमाल करके प्रयोग चलाने के लिए, सबसे पहले एक Experiment बनाएं. यह संसाधन आपके हिसाब से चलाए जाने वाले प्रयोग के बारे में कुछ प्रमुख जानकारी तय करता है, जैसे कि नाम और प्रयोग का प्रकार. इस चरण में, प्रयोग में शामिल किसी भी कैंपेन के बारे में न बताएं.

यहां Experiment के लिए कुछ मुख्य फ़ील्ड की खास जानकारी दी गई है:

  • name: हर एक्सपेरिमेंट का एक यूनीक नाम होना चाहिए.
  • description: यह एक वैकल्पिक फ़ील्ड है. इसे बाद में रेफ़रंस के लिए इस्तेमाल किया जा सकता है. इससे प्रयोग के चलने के तरीके पर कोई असर नहीं पड़ता.
  • suffix: सफ़िक्स को ट्रीटमेंट कैंपेन के नाम के आखिर में जोड़ा जाएगा, ताकि आप उन्हें कंट्रोल कैंपेन से अलग कर सकें. इन सिद्धांतों के बारे में एक्सपेरिमेंट आर्म पेज पर ज़्यादा जानकारी दी गई है.
  • type: किस तरह का एक्सपेरिमेंट चलाना है. यहां कई तरह के प्रयोग हैं, लेकिन उनमें ज़्यादातर सिस्टम प्रयोग हैं. अपने कस्टम प्रयोगों के लिए, आपको SEARCH_CUSTOM या DISPLAY_CUSTOM के बारे में बताना होगा.
  • status: एक्सपेरिमेंट बनाते समय, इस फ़ील्ड को SETUP पर सेट करें. बाद में, प्रयोग शुरू करने पर, इस फ़ील्ड की मदद से यह पता लगाया जा सकता है कि
  • start_date और end_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;
}

      

PHP

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;
}