Rekomendasi

Video: Pembahasan mendalam

Rekomendasi dapat meningkatkan kampanye Anda dengan beberapa cara:

  • Memperkenalkan fitur baru dan relevan
  • Dapatkan hasil maksimal dari anggaran Anda dengan bid, kata kunci, dan iklan yang ditingkatkan
  • Meningkatkan keseluruhan performa dan efisiensi kampanye

Untuk meningkatkan skor pengoptimalan, Anda dapat menggunakan RecommendationService untuk mengambil rekomendasi, lalu menerapkan atau menolaknya.

Skor pengoptimalan

Video: Pembahasan mendalam

Skor pengoptimalan adalah estimasi seberapa baik performa akun Google Ads Anda dan tersedia di tingkat Customer dan Campaign.

Customer.optimization_score_weight hanya tersedia untuk akun non-pengelola dan digunakan untuk menghitung skor pengoptimalan secara keseluruhan dari beberapa akun. Ambil skor pengoptimalan dan bobot skor pengoptimalan akun dan kalikan semuanya bersama-sama (Customer.optimization_score * Customer.optimization_score_weight) untuk menghitung skor pengoptimalan secara keseluruhan.

Ada metrik terkait pengoptimalan yang tersedia untuk laporan customer dan campaign:

  1. metrics.optimization_score_url memberikan deep link ke akun untuk melihat informasi tentang rekomendasi terkait di UI Google Ads.
  2. Nilai metrics.optimization_score_uplift menunjukkan seberapa besar skor pengoptimalan akan meningkat jika semua rekomendasi terkait diterapkan.

optimization_score_uplift hanyalah perkiraan. Hal ini disebabkan oleh peningkatan pengoptimalan yang dihitung satu per satu untuk setiap rekomendasi, dan efek gabungan dari penerapan beberapa rekomendasi mungkin bukan jumlah yang ketat dari setiap rekomendasi secara terpisah.

Jenis rekomendasi

Video: Menangani jenis yang tidak didukung

Google Ads API sepenuhnya mendukung jenis rekomendasi berikut:

RecommendationType Deskripsi
CAMPAIGN_BUDGET Perbaiki kampanye yang dibatasi anggaran
KEYWORD Menambahkan kata kunci baru
TEXT_AD Tambahkan rekomendasi iklan
TARGET_CPA_OPT_IN Ajukan bid dengan Target CPA
MAXIMIZE_CONVERSIONS_OPT_IN Bidding dengan Maksimalkan Konversi
ENHANCED_CPC_OPT_IN Ajukan bid dengan Enhanced CPC
SEARCH_PARTNERS_OPT_IN Perluas jangkauan dengan partner Penelusuran Google
MAXIMIZE_CLICKS_OPT_IN Ajukan Bid dengan Maksimalkan Klik
OPTIMIZE_AD_ROTATION Menggunakan rotasi iklan yang dioptimalkan
CALLOUT_EXTENSION Tambahkan ekstensi info ke kampanye
SITELINK_EXTENSION Tambahkan ekstensi sitelink ke kampanye
CALL_EXTENSION Tambahkan ekstensi panggilan ke kampanye
KEYWORD_MATCH_TYPE (deprecated) Mengubah jenis pencocokan kata kunci
MOVE_UNUSED_BUDGET Pindahkan aset yang tidak digunakan ke anggaran yang dibatasi
TARGET_ROAS_OPT_IN Ajukan bid dengan Target ROAS
FORECASTING_CAMPAIGN_BUDGET Memperbaiki kampanye yang diperkirakan akan dibatasi anggaran di masa mendatang
RESPONSIVE_SEARCH_AD Tambahkan iklan penelusuran responsif baru
MARGINAL_ROI_CAMPAIGN_BUDGET Menyesuaikan anggaran kampanye untuk meningkatkan ROI
USE_BROAD_MATCH_KEYWORD Gunakan pencocokan luas untuk kampanye berbasis konversi dengan bidding otomatis
RESPONSIVE_SEARCH_AD_ASSET Menambahkan aset iklan penelusuran responsif ke iklan
UPGRADE_SMART_SHOPPING_CAMPAIGN_TO_PERFORMANCE_MAX Upgrade kampanye Shopping Pintar ke kampanye Performa Maksimal
RESPONSIVE_SEARCH_AD_IMPROVE_AD_STRENGTH Tingkatkan daya iklan penelusuran responsif

Mengambil rekomendasi

Video: Live coding

Seperti sebagian besar entity lainnya di Google Ads API, objek Recommendation diambil menggunakan GoogleAdsService.SearchStream dengan kueri Bahasa Kueri Google Ads.

Untuk setiap jenis rekomendasi, detail rekomendasi diberikan di kolom recommendation tertentu dengan jenis tertentu:

RecommendationType recommendation Jenis
CAMPAIGN_BUDGET campaign_budget_recommendation CampaignBudgetRecommendation
KEYWORD keyword_recommendation KeywordRecommendation
TEXT_AD text_ad_recommendation TextAdRecommendation
TARGET_CPA_OPT_IN target_cpa_opt_in_recommendation TargetCpaOptInRecommendation
MAXIMIZE_CONVERSIONS_OPT_IN maximize_conversions_opt_in_recommendation MaximizeConversionsOptInRecommendation
ENHANCED_CPC_OPT_IN enhanced_cpc_opt_in_recommendation EnhancedCpcOptInRecommendation
SEARCH_PARTNERS_OPT_IN search_partners_opt_in_recommendation SearchPartnersOptInRecommendation
MAXIMIZE_CLICKS_OPT_IN maximize_clicks_opt_in_recommendation MaximizeClicksOptInRecommendation
OPTIMIZE_AD_ROTATION optimize_ad_rotation_recommendation OptimizeAdRotationRecommendation
CALLOUT_EXTENSION callout_extension_recommendation CalloutExtensionRecommendation
SITELINK_EXTENSION sitelink_extension_recommendation SitelinkExtensionRecommendation
CALL_EXTENSION call_extension_recommendation CallExtensionRecommendation
KEYWORD_MATCH_TYPE (tidak digunakan lagi) keyword_match_type_recommendation KeywordMatchTypeRecommendation
MOVE_UNUSED_BUDGET move_unused_budget_recommendation MoveUnusedBudgetRecommendation
TARGET_ROAS_OPT_IN target_roas_opt_in_recommendation TargetRoasOptInRecommendation
FORECASTING_CAMPAIGN_BUDGET forecasting_campaign_budget_recommendation CampaignBudgetRecommendation
RESPONSIVE_SEARCH_AD responsive_search_ad_recommendation ResponsiveSearchAdRecommendation
MARGINAL_ROI_CAMPAIGN_BUDGET marginal_roi_campaign_budget_recommendation CampaignBudgetRecommendation
USE_BROAD_MATCH_KEYWORD use_broad_match_keyword_recommendation UseBroadMatchKeywordRecommendation
RESPONSIVE_SEARCH_AD_ASSET responsive_search_ad_asset_recommendation ResponsiveSearchAdAssetRecommendation

Kode contoh berikut mengambil semua rekomendasi jenis TEXT_AD yang tersedia dan yang ditolak dari akun, serta mencetak beberapa detailnya:

Java

private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
  try (GoogleAdsServiceClient googleAdsServiceClient =
      googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
    String query =
        "SELECT recommendation.type, "
            + "recommendation.campaign, "
            + "recommendation.text_ad_recommendation "
            + "FROM recommendation "
            + "WHERE recommendation.type = TEXT_AD";

    // Creates a request that will retrieve all recommendations using pages of the
    // specified page size.
    SearchGoogleAdsRequest request =
        SearchGoogleAdsRequest.newBuilder()
            .setCustomerId(Long.toString(customerId))
            .setPageSize(PAGE_SIZE)
            .setQuery(query)
            .build();
    // Issues the search request.
    SearchPagedResponse searchPagedResponse = googleAdsServiceClient.search(request);

    // Iterates over all rows in all pages and prints the requested field values for the
    // recommendation in each row.
    for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) {
      Recommendation recommendation = googleAdsRow.getRecommendation();
      Ad recommendedAd = recommendation.getTextAdRecommendation().getAd();

      System.out.printf(
          "Recommendation ('%s') was found for campaign '%s':%n",
          recommendation.getResourceName(), recommendation.getCampaign());
      if (recommendedAd.hasExpandedTextAd()) {
        ExpandedTextAdInfo eta = recommendedAd.getExpandedTextAd();
        System.out.printf(
            "\tHeadline 1 = '%s'%n" + "\tHeadline 2 = '%s'%n" + "\tDescription = '%s'%n",
            eta.getHeadlinePart1(), eta.getHeadlinePart2(), eta.getDescription());
      }
      if (recommendedAd.getDisplayUrl() != null) {
        System.out.printf("\tDisplay URL = '%s'%n", recommendedAd.getDisplayUrl());
      }
      for (String url : recommendedAd.getFinalUrlsList()) {
        System.out.printf("\tFinal URL = '%s'%n", url);
      }
      for (String url : recommendedAd.getFinalMobileUrlsList()) {
        System.out.printf("\tFinal Mobile URL = '%s'%n", url);
      }
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId)
{
    // Get the GoogleAdsServiceClient .
    GoogleAdsServiceClient service = client.GetService(Services.V11.GoogleAdsService);

    string query =
        @"SELECT
        recommendation.type,
        recommendation.campaign,
        recommendation.text_ad_recommendation
    FROM
        recommendation
    WHERE
        recommendation.type = TEXT_AD";

    // Create a request that will retrieve all recommendations using pages of the
    // specified page size.
    SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
    {
        CustomerId = customerId.ToString(),
        PageSize = PAGE_SIZE,
        Query = query
    };

    try
    {
        // Issue the search request.
        PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse =
            service.Search(customerId.ToString(), query);

        // Iterates over all rows in all pages and prints the requested field values
        // for the recommendation in each row.
        foreach (GoogleAdsRow googleAdsRow in searchPagedResponse)
        {
            Recommendation recommendation = googleAdsRow.Recommendation;
            // ...
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId)
{
    $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
    // Creates a query that retrieves recommendations for text ads.
    $query = 'SELECT recommendation.type, recommendation.campaign, '
        . 'recommendation.text_ad_recommendation '
        . 'FROM recommendation '
        . 'WHERE recommendation.type = TEXT_AD';

    // Issues a search request by specifying page size.
    $response =
        $googleAdsServiceClient->search($customerId, $query, ['pageSize' => self::PAGE_SIZE]);

    // Iterates over all rows in all pages and prints the requested field values for
    // the recommendation in each row.
    foreach ($response->iterateAllElements() as $googleAdsRow) {
        /** @var GoogleAdsRow $googleAdsRow */
        $recommendation = $googleAdsRow->getRecommendation();
        printf(
            "Recommendation with resource name '%s' was found for campaign "
            . "with resource name '%s':%s",
            $recommendation->getResourceName(),
            $recommendation->getCampaign(),
            PHP_EOL
        );
        $recommendedAd = $recommendation->getTextAdRecommendation()->getAd();
        if (!is_null($recommendedAd->getExpandedTextAd())) {
            $recommendedExpandedTextAd = $recommendedAd->getExpandedTextAd();
            printf(
                "\tHeadline part 1 is '%s'.%s",
                $recommendedExpandedTextAd->getHeadlinePart1(),
                PHP_EOL
            );
            printf(
                "\tHeadline part 2 is '%s'.%s",
                $recommendedExpandedTextAd->getHeadlinePart2(),
                PHP_EOL
            );
            printf(
                "\tDescription is '%s'%s",
                $recommendedExpandedTextAd->getDescription(),
                PHP_EOL
            );
        }
        if (!is_null($recommendedAd->getDisplayUrl())) {
            printf("\tDisplay URL is '%s'.%s", $recommendedAd->getDisplayUrl(), PHP_EOL);
        }
        foreach ($recommendedAd->getFinalUrls() as $finalUrl) {
            /** @var string $finalUrl */
            printf("\tFinal URL is '%s'.%s", $finalUrl, PHP_EOL);
        }
        foreach ($recommendedAd->getFinalMobileUrls() as $finalMobileUrl) {
            /** @var string $finalMobileUrl */
            printf("\tFinal Mobile URL is '%s'.%s", $finalMobileUrl, PHP_EOL);
        }
    }
}
      

Python

def main(client, customer_id):
    ga_service = client.get_service("GoogleAdsService")

    query = """
        SELECT
          recommendation.type,
          recommendation.campaign,
          recommendation.text_ad_recommendation
        FROM recommendation
        WHERE recommendation.type = TEXT_AD"""

    search_request = client.get_type("SearchGoogleAdsStreamRequest")
    search_request.customer_id = customer_id
    search_request.query = query
    stream = ga_service.search_stream(request=search_request)

    for batch in stream:
        for row in batch.results:
            recommendation = row.recommendation
            recommended_ad = recommendation.text_ad_recommendation.ad
            print(
                f'Recommendation ("{recommendation.resource_name}") '
                f'was found for campaign "{recommendation.campaign}".'
            )

            if recommended_ad.display_url:
                print(f'\tDisplay URL = "{recommended_ad.display_url}"')

            for url in recommended_ad.final_urls:
                print(f'\tFinal URL = "{url}"')

            for url in recommended_ad.final_mobile_urls:
                print(f'\tFinal Mobile URL = "{url}"')
      

Ruby

def get_text_ad_recommendations(customer_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  ga_service = client.service.google_ads

  query = <<~QUERY
    SELECT recommendation.type, recommendation.campaign,
        recommendation.text_ad_recommendation
    FROM recommendation
    WHERE recommendation.type = TEXT_AD
  QUERY

  response = ga_service.search(
    customer_id: customer_id,
    query: query,
    page_size: PAGE_SIZE,
  )

  response.each do |row|
    recommendation = row.recommendation
    recommended_ad = recommendation.text_ad_recommendation.ad

    puts "Recommendation ('#{recommendation.resource_name}') was found for "\
        "campaign '#{recommendation.campaign}'."
    if recommended_ad.expanded_text_ad
      eta = recommended_ad.expanded_text_ad
      puts "\tHeadline 1 = '#{eta.headline_part1}'\n\tHeadline2 = '#{eta.headline_part2}'\n" +
          "\tDescription = '#{eta.description}'"
    end
    if recommended_ad.display_url
      puts "\tDisplay URL = '#{recommended_ad.display_url}'"
    end
    recommended_ad.final_urls.each do |url|
      puts "\tFinal Url = '#{url}'"
    end
    recommended_ad.final_mobile_urls.each do |url|
      puts "\tFinal Mobile Url = '#{url}'"
    end
  end
end
      

Perl

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

  # Creates the search query.
  my $search_query =
    "SELECT recommendation.type, recommendation.campaign, " .
    "recommendation.text_ad_recommendation " .
    "FROM recommendation WHERE recommendation.type = TEXT_AD";

  # Create a search Google Ads request that will retrieve all recommendations for
  # text ads using pages of the specified page size.
  my $search_request =
    Google::Ads::GoogleAds::V11::Services::GoogleAdsService::SearchGoogleAdsRequest
    ->new({
      customerId => $customer_id,
      query      => $search_query,
      pageSize   => PAGE_SIZE
    });

  # Get the GoogleAdsService.
  my $google_ads_service = $api_client->GoogleAdsService();

  my $iterator = Google::Ads::GoogleAds::Utils::SearchGoogleAdsIterator->new({
    service => $google_ads_service,
    request => $search_request
  });

  # Iterate over all rows in all pages and print the requested field values for
  # the recommendation in each row.
  while ($iterator->has_next) {
    my $google_ads_row = $iterator->next;
    my $recommendation = $google_ads_row->{recommendation};
    printf
      "Recommendation '%s' was found for campaign '%s':\n",
      $recommendation->{resourceName},
      $recommendation->{campaign};

    my $recommended_ad = $recommendation->{textAdRecommendation}{ad};
    if ($recommended_ad->{expandedTextAd}) {
      my $recommended_expanded_text_ad = $recommended_ad->{expandedTextAd};

      printf "\tHeadline part 1 is '%s'.\n" .
        "\tHeadline part 2 is '%s'.\n" . "\tDescription is '%s'.\n",
        $recommended_expanded_text_ad->{headlinePart1},
        $recommended_expanded_text_ad->{headlinePart2},
        $recommended_expanded_text_ad->{description};
    }

    if ($recommended_ad->{displayUrl}) {
      printf "\tDisplay URL is '%s'.\n", $recommended_ad->{displayUrl};
    }

    foreach my $final_url (@{$recommended_ad->{finalUrls}}) {
      printf "\tFinal URL is '%s'.\n", $final_url;
    }

    foreach my $final_mobile_url (@{$recommended_ad->{finalMobileUrls}}) {
      printf "\tFinal Mobile URL is '%s'.\n", $final_mobile_url;
    }
  }

  return 1;
}
      

Ambil tindakan

Rekomendasi apa pun yang diambil dapat diterapkan atau ditolak.

Bergantung pada jenis rekomendasi, rekomendasi dapat berubah setiap hari atau bahkan beberapa kali dalam sehari. Jika hal itu terjadi, resource_name objek rekomendasi tidak akan digunakan lagi setelah rekomendasi diambil.

Sebaiknya ambil tindakan berdasarkan rekomendasi segera setelah pengambilan.

Menerapkan rekomendasi

Video: Pembahasan mendalam

Setelan akun untuk rekomendasi yang diterapkan secara otomatis tidak didukung di Google Ads API, tetapi, Anda dapat menerapkan perilaku serupa untuk jenis rekomendasi yang sepenuhnya didukung oleh Google Ads API. Lihat contoh kode DetectAndApplyRecommendations untuk mempelajari lebih lanjut.

Anda dapat menerapkan rekomendasi yang aktif atau ditolak dengan metode ApplyRecommendation dari RecommendationService.

Jenis rekomendasi dapat memiliki parameter wajib atau opsional. Sebagian besar rekomendasi dilengkapi dengan nilai yang direkomendasikan yang digunakan secara default; lihat detail rekomendasi.

Gunakan kolom apply_parameters pada ApplyRecommendationOperation untuk menerapkan rekomendasi dengan parameter value tertentu. Setiap jenis rekomendasi yang sesuai memiliki kolomnya sendiri:

RecommendationType apply_parameters Jenis
CAMPAIGN_BUDGET campaign_budget CampaignBudgetParameters
KEYWORD keyword KeywordParameters
TEXT_AD text_ad TextAdParameters
TARGET_CPA_OPT_IN target_cpa_opt_in TargetCpaOptInParameters
MAXIMIZE_CONVERSIONS_OPT_IN - -
ENHANCED_CPC_OPT_IN - -
SEARCH_PARTNERS_OPT_IN - -
MAXIMIZE_CLICKS_OPT_IN - -
OPTIMIZE_AD_ROTATION - -
CALLOUT_EXTENSION callout_extension CalloutExtensionParameters
SITELINK_EXTENSION sitelink_extension SitelinkExtensionParameters
CALL_EXTENSION call_extension CallExtensionParameters
KEYWORD_MATCH_TYPE (tidak digunakan lagi) - -
MOVE_UNUSED_BUDGET move_unused_budget MoveUnusedBudgetParameters
TARGET_ROAS_OPT_IN target_roas_opt_in TargetRoasOptInParameters
FORECASTING_CAMPAIGN_BUDGET campaign_budget CampaignBudgetParameters
RESPONSIVE_SEARCH_AD responsive_search_ad ResponsiveSearchAdParameters
MARGINAL_ROI_CAMPAIGN_BUDGET campaign_budget CampaignBudgetParameters
USE_BROAD_MATCH_KEYWORD use_broad_match_keyword UseBroadMatchKeywordRecommendation
RESPONSIVE_SEARCH_AD_ASSET responsive_search_ad_asset ResponsiveSearchAdAssetParameters

Contoh kode berikut menggambarkan cara menerapkan rekomendasi dengan parameter penerapan yang direkomendasikan:

Java

private void runExample(
    GoogleAdsClient googleAdsClient, long customerId, String recommendationId) {
  String recommendationResourceName = ResourceNames.recommendation(customerId, recommendationId);

  ApplyRecommendationOperation.Builder operationBuilder =
      ApplyRecommendationOperation.newBuilder().setResourceName(recommendationResourceName);
  // Each recommendation types has optional parameters to override the recommended values.
  // This is an example to override a recommended ad when a TextAdRecommendation is applied.
  // Please read
  // https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation
  // for details.
  // Note that additional import statements are needed for this example to work. And also, please
  // replace INSERT_AD_ID_HERE with a valid ad ID below.
  //
  // Ad overrideAd = Ad.newBuilder().setId(Long.parseLong("INSERT_AD_ID_HERE")).build();
  // operationBuilder.setTextAd(TextAdParameters.newBuilder().
  //     setAd(overrideAd).build()).build();
  List<ApplyRecommendationOperation> operations = new ArrayList<>();
  operations.add(operationBuilder.build());

  try (RecommendationServiceClient recommendationServiceClient =
      googleAdsClient.getLatestVersion().createRecommendationServiceClient()) {
    ApplyRecommendationResponse response =
        recommendationServiceClient.applyRecommendation(Long.toString(customerId), operations);
    System.out.printf("Applied %d recommendation:%n", response.getResultsCount());
    for (ApplyRecommendationResult result : response.getResultsList()) {
      System.out.println(result.getResourceName());
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId, long recommendationId)
{
    // Get the RecommendationServiceClient.
    RecommendationServiceClient service = client.GetService(
        Services.V11.RecommendationService);

    ApplyRecommendationOperation operation = new ApplyRecommendationOperation()
    {
        ResourceName = ResourceNames.Recommendation(customerId, recommendationId),

        // Each recommendation types has optional parameters to override the recommended
        // values. For example, you can override a recommended ad when a
        // TextAdRecommendation is applied, as shown below.
        // Please read https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation
        // for details.
        // TextAd = new TextAdParameters() {
        //   Ad = new Ad() {
        //     Id = long.Parse("INSERT_AD_ID_HERE")
        //   }
        // }
    };

    try
    {
        ApplyRecommendationResponse response = service.ApplyRecommendation(
            customerId.ToString(), new ApplyRecommendationOperation[] {
                operation
            });
        Console.WriteLine($"Applied {0} recommendation(s):", response.Results.Count);
        foreach (ApplyRecommendationResult result in response.Results)
        {
            Console.WriteLine($"- {result.ResourceName}");
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

public static function runExample(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $recommendationId
) {
    $recommendationResourceName =
        ResourceNames::forRecommendation($customerId, $recommendationId);

    $applyRecommendationOperation = new ApplyRecommendationOperation();
    $applyRecommendationOperation->setResourceName($recommendationResourceName);

    // Each recommendation type has optional parameters to override the recommended values.
    // This is an example to override a recommended ad when a TextAdRecommendation is applied.
    // For details, please read
    // https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation.
    /*
    $overridingAd = new Ad([
        'id' => 'INSERT_AD_ID_AS_INTEGER_HERE'
    ]);
    $applyRecommendationOperation->setTextAd(new TextAdParameters(['ad' => $overridingAd]));
    */
    // Issues a mutate request to apply the recommendation.
    $recommendationServiceClient = $googleAdsClient->getRecommendationServiceClient();
    $response = $recommendationServiceClient->applyRecommendation(
        $customerId,
        [$applyRecommendationOperation]
    );
    /** @var Recommendation $appliedRecommendation */
    $appliedRecommendation = $response->getResults()[0];

    printf(
        "Applied recommendation with resource name: '%s'.%s",
        $appliedRecommendation->getResourceName(),
        PHP_EOL
    );
}
      

Python

def main(client, customer_id, recommendation_id):
    recommendation_service = client.get_service("RecommendationService")

    apply_recommendation_operation = client.get_type(
        "ApplyRecommendationOperation"
    )

    apply_recommendation_operation.resource_name = (
        recommendation_service.recommendation_path(
            customer_id, recommendation_id
        )
    )

    # This is where we override the recommended ad when a TextAdRecommendation is applied.
    # override_ad = client.get_type("Ad")
    # override_ad.resource_name = "INSERT_AD_ID_HERE"
    # apply_recommendation_operation.text_ad.ad = override_ad

    recommendation_response = recommendation_service.apply_recommendation(
        customer_id=customer_id, operations=[apply_recommendation_operation]
    )

    print(
        "Applied recommendation with resource name: "
        f"'{recommendation_response.results[0].resource_name}'"
    )
      

Ruby

def apply_recommendation(customer_id, recommendation_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  recommendation_resource =
      client.path.recommendation(customer_id, recommendation_id)
  apply_recommendation_operation = client.operation.apply_recommendation
  apply_recommendation_operation.resource_name = recommendation_resource

  # Each recommendation type has optional parameters to override the recommended
  # values. This is an example to override a recommended ad when a
  # TextAdRecommendation is applied.
  # For details, please read
  # https://developers.google.com/google-ads/api/reference/rpc/google.ads.google_ads.v1.services#google.ads.google_ads.v1.services.ApplyRecommendationOperation
  #
  # text_ad_parameters = client.resource.text_ad_parameters do |tap|
  #   tap.ad = client.resource.ad do |ad|
  #     ad.id = "INSERT_AD_ID_AS_INTEGER_HERE"
  #   end
  # end
  # apply_recommendation_operation.text_ad = text_ad_parameters

  # Issues a mutate request to apply the recommendation.
  recommendation_service = client.service.recommendation
  response = recommendation_service.apply_recommendation(
    customer_id: customer_id,
    operations: [apply_recommendation_operation],
  )
  applied_recommendation = response.results.first

  puts "Applied recommendation with resource name: '#{applied_recommendation.resource_name}'."
end
      

Perl

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

  my $recommendation_resource_name =
    Google::Ads::GoogleAds::V11::Utils::ResourceNames::recommendation(
    $customer_id, $recommendation_id);

  # Create an apply recommendation operation.
  my $apply_recommendation_operation =
    Google::Ads::GoogleAds::V11::Services::RecommendationService::ApplyRecommendationOperation
    ->new({
      resourceName => $recommendation_resource_name
    });

  # Each recommendation type has optional parameters to override the recommended values.
  # This is an example to override a recommended ad when a TextAdRecommendation is applied.
  # For details, please read
  # https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation.
  #
  # my $overriding_ad = Google::Ads::GoogleAds::V11::Resources::Ad->new({
  #   id => "INSERT_AD_ID_AS_INTEGER_HERE"
  # });
  # my $text_ad_parameters =
  #   Google::Ads::GoogleAds::V11::Services::RecommendationService::TextAdParameters
  #   ->new({ad => $overriding_ad});
  # $apply_recommendation_operation->{textAd} = $text_ad_parameters;

  # Apply the recommendation.
  my $apply_recommendation_response =
    $api_client->RecommendationService()->apply({
      customerId => $customer_id,
      operations => [$apply_recommendation_operation]});

  printf "Applied recommendation with resource name: '%s'.\n",
    $apply_recommendation_response->{results}[0]{resourceName};

  return 1;
}
      

Tonton video ini untuk mempelajari lebih lanjut

Terapkan parameter

Massal

Error

Pengujian

Menolak rekomendasi

Video: Pembahasan mendalam

Anda dapat menolak rekomendasi dengan RecommendationService. Struktur kodenya mirip dengan menerapkan rekomendasi, tetapi Anda menggunakan DismissRecommendationOperation dan RecommendationService.DismissRecommendation.

Tonton video ini untuk mempelajari lebih lanjut

Massal

Error

Pengujian