最佳化分數和最佳化建議

影片:深入探討

最佳化建議可透過下列幾種方式改善廣告活動:

  • 介紹實用新功能
  • 調整出價、關鍵字和廣告,讓預算發揮更大效益
  • 提升廣告活動的整體成效和效率

如要提高最佳化分數,請使用 RecommendationService 擷取建議,然後視情況套用或關閉建議。您也可以使用 RecommendationSubscriptionService 訂閱自動套用最佳化建議。

最佳化分數

影片:最佳化分數

最佳化分數代表 Google Ads 帳戶的預期成效,並提供CustomerCampaign層級的資料。

Customer.optimization_score_weight 僅適用於非管理員帳戶,用於計算多個帳戶的整體最佳化分數。擷取帳戶的最佳化分數和最佳化分數權重,然後將兩者相乘 (Customer.optimization_score * Customer.optimization_score_weight),即可計算整體最佳化分數。

customercampaign 報表提供下列最佳化相關指標:

  1. metrics.optimization_score_url 提供帳戶的深層連結,可在 Google Ads 使用者介面中查看相關建議的資訊。
  2. metrics.optimization_score_uplift 這個百分比值表示採用所有相關最佳化建議後,最佳化分數預期會有的升幅。這是根據所有可用的最佳化建議整體估算,而非各項建議升幅分數的總和。

如要將傳回的建議分組並排序,您可以使用查詢中的 segments.recommendation_type,依建議類型劃分這兩項指標。

推薦類型

完全支援的最佳化建議類型

RecommendationType 說明
CAMPAIGN_BUDGET 修正受到預算限制的廣告活動
KEYWORD 新增關鍵字
TEXT_AD 新增廣告建議
TARGET_CPA_OPT_IN 使用目標單次動作出價
MAXIMIZE_CONVERSIONS_OPT_IN 使用「盡量爭取轉換」出價
MAXIMIZE_CONVERSION_VALUE_OPT_IN 使用「盡量提高轉換價值」出價
ENHANCED_CPC_OPT_IN 使用成本效益管理系統出價
MAXIMIZE_CLICKS_OPT_IN 使用「盡量爭取點擊」出價
OPTIMIZE_AD_ROTATION 使用最佳化廣告輪播
MOVE_UNUSED_BUDGET 將未用到的預算轉挪給預算不足的廣告活動
TARGET_ROAS_OPT_IN 採用目標廣告投資報酬率出價
FORECASTING_CAMPAIGN_BUDGET 修正預計未來會受到預算限制的廣告活動
RESPONSIVE_SEARCH_AD 新增回應式搜尋廣告
MARGINAL_ROI_CAMPAIGN_BUDGET 調整廣告活動預算,提高投資報酬率
USE_BROAD_MATCH_KEYWORD 針對採用自動出價的轉換型廣告活動,使用廣泛比對
RESPONSIVE_SEARCH_AD_ASSET 在廣告中新增回應式搜尋廣告素材資源
RESPONSIVE_SEARCH_AD_IMPROVE_AD_STRENGTH 提高回應式搜尋廣告的優異度
DISPLAY_EXPANSION_OPT_IN 更新廣告活動,改用多媒體廣告擴展功能
SEARCH_PARTNERS_OPT_IN 透過 Google 搜尋聯播網夥伴擴大觸及範圍
CUSTOM_AUDIENCE_OPT_IN 建立自訂目標對象
IMPROVE_DEMAND_GEN_AD_STRENGTH 提升需求開發廣告活動的廣告優異度
UPGRADE_SMART_SHOPPING_CAMPAIGN_TO_PERFORMANCE_MAX 將智慧購物廣告活動升級為最高成效廣告活動
UPGRADE_LOCAL_CAMPAIGN_TO_PERFORMANCE_MAX 將舊版地區廣告活動升級為最高成效廣告活動
SHOPPING_MIGRATE_REGULAR_SHOPPING_CAMPAIGN_OFFERS_TO_PERFORMANCE_MAX 將標準購物廣告活動指定的產品遷移至現有的最高成效廣告活動
MIGRATE_DYNAMIC_SEARCH_ADS_CAMPAIGN_TO_PERFORMANCE_MAX 將動態搜尋廣告遷移至最高成效廣告活動
PERFORMANCE_MAX_OPT_IN 在帳戶中建立最高成效廣告活動
IMPROVE_PERFORMANCE_MAX_AD_STRENGTH 將最高成效廣告活動的素材資源群組強度提升至「極佳」評分
PERFORMANCE_MAX_FINAL_URL_OPT_IN 為最高成效廣告活動啟用最終到達網址擴展功能
RAISE_TARGET_CPA_BID_TOO_LOW 目標單次動作出價過低,導致轉換次數很少或沒有時,請提高目標單次動作出價
FORECASTING_SET_TARGET_ROAS 在預計流量會增加的季節性活動前提高預算,並將出價策略從「盡量提高轉換價值」改為「目標廣告投資報酬率」
LEAD_FORM_ASSET 在廣告活動中加入待開發客戶表單素材資源
CALLOUT_ASSET 在廣告活動或客戶層級新增摘要素材資源
SITELINK_ASSET 在廣告活動或客戶層級新增網站連結素材資源
CALL_ASSET 在廣告活動或客戶層級新增電話素材資源
SHOPPING_ADD_AGE_GROUP 為因缺少年齡層而遭到降級的商品新增年齡層屬性
SHOPPING_ADD_COLOR 為因缺少顏色而遭到降級的商品新增顏色
SHOPPING_ADD_GENDER 為因缺少性別而遭到降級的商品新增性別
SHOPPING_ADD_GTIN 為因缺少全球交易品項識別碼而遭到降級的商品新增全球交易品項識別碼
SHOPPING_ADD_MORE_IDENTIFIERS 為因缺少 ID 而遭到降級的商品新增更多 ID
SHOPPING_ADD_SIZE 為因缺少尺寸而遭到降級的商品新增尺寸
SHOPPING_ADD_PRODUCTS_TO_CAMPAIGN 為廣告活動加入要放送的產品
SHOPPING_FIX_DISAPPROVED_PRODUCTS 修正遭拒登的產品
SHOPPING_TARGET_ALL_OFFERS 建立指定所有產品的通用產品廣告活動
SHOPPING_FIX_SUSPENDED_MERCHANT_CENTER_ACCOUNT 修正 Merchant Center 帳戶停權問題
SHOPPING_FIX_MERCHANT_CENTER_ACCOUNT_SUSPENSION_WARNING 修正 Merchant Center 帳戶停權警告問題
DYNAMIC_IMAGE_EXTENSION_OPT_IN 在帳戶中啟用動態圖片額外資訊
RAISE_TARGET_CPA 提高目標單次動作出價
LOWER_TARGET_ROAS 調降目標廣告投資報酬率
FORECASTING_SET_TARGET_CPA 為尚未指定目標單次動作出價的廣告活動設定目標單次動作出價,以因應預計會增加流量的季節性活動
SET_TARGET_CPA 為未指定目標單次動作出價的廣告活動設定目標單次動作出價
SET_TARGET_ROAS 為未指定目標廣告投資報酬率的廣告活動設定目標廣告投資報酬率
REFRESH_CUSTOMER_MATCH_LIST 更新過去 90 天內未更新的顧客名單
IMPROVE_GOOGLE_TAG_COVERAGE 在更多網頁上部署 Google 代碼
KEYWORD_MATCH_TYPE (已淘汰) 已淘汰,請改用 USE_BROAD_MATCH_KEYWORD

觀看這部影片瞭解詳情

處理不支援的型別

擷取建議

影片:即時編碼

與 Google Ads API 中的大多數其他實體一樣,Recommendation物件是透過使用 GoogleAdsService.SearchStream 搭配 Google Ads 查詢語言查詢來擷取。

每種最佳化建議的詳細資料都會顯示在專屬欄位中。舉例來說,CAMPAIGN_BUDGET 建議詳細資料位於 campaign_budget_recommendation 欄位中,並包裝在 CampaignBudgetRecommendation 物件中。

recommendation 聯集欄位中,找出所有建議專屬欄位。

建議影響

部分最佳化建議類型會填入最佳化建議的 impact 欄位。RecommendationImpact 包含套用建議後,對帳戶成效的預估影響。impact.base_metricsimpact.potential_metrics 欄位提供下列建議指標

  • impressions

  • clicks

  • cost_micros

  • conversions

  • all_conversions

  • video_views

即使填入 impact 欄位,指標的可用性仍會因建議類型和廣告活動類型等因素而異。一般來說,請先檢查各項影響指標是否可用,再嘗試使用。

程式碼範例

下列程式碼範例會從帳戶擷取所有可用的已排除建議,並列印部分詳細資料:KEYWORD

Java

try (GoogleAdsServiceClient googleAdsServiceClient =
        googleAdsClient.getLatestVersion().createGoogleAdsServiceClient();
    RecommendationServiceClient recommendationServiceClient =
        googleAdsClient.getLatestVersion().createRecommendationServiceClient()) {
  // Creates a query that retrieves keyword recommendations.
  String query =
      "SELECT recommendation.resource_name, "
          + "  recommendation.campaign, "
          + "  recommendation.keyword_recommendation "
          + "FROM recommendation "
          + "WHERE recommendation.type = KEYWORD";
  // Constructs the SearchGoogleAdsStreamRequest.
  SearchGoogleAdsStreamRequest request =
      SearchGoogleAdsStreamRequest.newBuilder()
          .setCustomerId(Long.toString(customerId))
          .setQuery(query)
          .build();

  // Issues the search stream request to detect keyword recommendations that exist for the
  // customer account.
  ServerStream<SearchGoogleAdsStreamResponse> stream =
      googleAdsServiceClient.searchStreamCallable().call(request);

  // Creates apply operations for all the recommendations found.
  List<ApplyRecommendationOperation> applyRecommendationOperations = new ArrayList<>();
  for (SearchGoogleAdsStreamResponse response : stream) {
    for (GoogleAdsRow googleAdsRow : response.getResultsList()) {
      Recommendation recommendation = googleAdsRow.getRecommendation();
      System.out.printf(
          "Keyword recommendation '%s' was found for campaign '%s'%n",
          recommendation.getResourceName(), recommendation.getCampaign());
      KeywordInfo keyword = recommendation.getKeywordRecommendation().getKeyword();
      System.out.printf("\tKeyword = '%s'%n", keyword.getText());
      System.out.printf("\tMatch type = '%s'%n", keyword.getMatchType());

      // Creates an ApplyRecommendationOperation that will apply this recommendation, and adds
      // it to the list of operations.
      applyRecommendationOperations.add(buildRecommendationOperation(recommendation));
    }
  }
      

C#

// Get the GoogleAdsServiceClient.
GoogleAdsServiceClient googleAdsService = client.GetService(
    Services.V20.GoogleAdsService);

// Creates a query that retrieves keyword recommendations.
string query = "SELECT recommendation.resource_name, " +
    "recommendation.campaign, recommendation.keyword_recommendation " +
    "FROM recommendation WHERE " +
    $"recommendation.type = KEYWORD";

List<ApplyRecommendationOperation> operations =
    new List<ApplyRecommendationOperation>();

try
{
    // Issue a search request.
    googleAdsService.SearchStream(customerId.ToString(), query,
        delegate (SearchGoogleAdsStreamResponse resp)
        {
            Console.WriteLine($"Found {resp.Results.Count} recommendations.");
            foreach (GoogleAdsRow googleAdsRow in resp.Results)
            {
                Recommendation recommendation = googleAdsRow.Recommendation;
                Console.WriteLine("Keyword recommendation " +
                    $"{recommendation.ResourceName} was found for campaign " +
                    $"{recommendation.Campaign}.");

                if (recommendation.KeywordRecommendation != null)
                {
                    KeywordInfo keyword =
                        recommendation.KeywordRecommendation.Keyword;
                    Console.WriteLine($"Keyword = {keyword.Text}, type = " +
                        "{keyword.MatchType}");
                }

                operations.Add(
                    BuildApplyRecommendationOperation(recommendation.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

$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves keyword recommendations.
$query = 'SELECT recommendation.resource_name, recommendation.campaign, '
    . 'recommendation.keyword_recommendation '
    . 'FROM recommendation '
    . 'WHERE recommendation.type = KEYWORD ';
// Issues a search request to detect keyword recommendations that exist for the
// customer account.
$response =
    $googleAdsServiceClient->search(SearchGoogleAdsRequest::build($customerId, $query));

$operations = [];
// 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(
        "Keyword recommendation with resource name '%s' was found for campaign "
        . "with resource name '%s':%s",
        $recommendation->getResourceName(),
        $recommendation->getCampaign(),
        PHP_EOL
    );
    if (!is_null($recommendation->getKeywordRecommendation())) {
        $keyword = $recommendation->getKeywordRecommendation()->getKeyword();
        printf(
            "\tKeyword = '%s'%s\ttype = '%s'%s",
            $keyword->getText(),
            PHP_EOL,
            KeywordMatchType::name($keyword->getMatchType()),
            PHP_EOL
        );
    }
    // Creates an ApplyRecommendationOperation that will be used to apply this
    // recommendation, and adds it to the list of operations.
    $operations[] = self::buildRecommendationOperation($recommendation->getResourceName());
}
      

Python

googleads_service = client.get_service("GoogleAdsService")
query = f"""
    SELECT
      recommendation.campaign,
      recommendation.keyword_recommendation
    FROM recommendation
    WHERE
      recommendation.type = KEYWORD"""

# Detects keyword recommendations that exist for the customer account.
response = googleads_service.search(customer_id=customer_id, query=query)

operations = []
for row in response.results:
    recommendation = row.recommendation
    print(
        f"Keyword recommendation ('{recommendation.resource_name}') "
        f"was found for campaign '{recommendation.campaign}."
    )

    keyword = recommendation.keyword_recommendation.keyword
    print(
        f"\tKeyword = '{keyword.text}'\n" f"\tType = '{keyword.match_type}'"
    )

    # Create an ApplyRecommendationOperation that will be used to apply
    # this recommendation, and add it to the list of operations.
    operations.append(
        build_recommendation_operation(client, recommendation.resource_name)
    )
      

小茹

query = <<~QUERY
  SELECT recommendation.resource_name, recommendation.campaign,
      recommendation.keyword_recommendation
  FROM recommendation
  WHERE recommendation.type = KEYWORD
QUERY

google_ads_service = client.service.google_ads

response = google_ads_service.search(
  customer_id: customer_id,
  query: query,
)

operations = response.each do |row|
  recommendation = row.recommendation

  puts "Keyword recommendation ('#{recommendation.resource_name}') was found for "\
    "campaign '#{recommendation.campaign}'."

  if recommendation.keyword_recommendation
    keyword = recommendation.keyword_recommendation.keyword
    puts "\tKeyword = '#{keyword.text}'"
    puts "\ttype = '#{keyword.match_type}'"
  end

  build_recommendation_operation(client, recommendation.resource_name)
end
      

Perl

# Create the search query.
my $search_query =
  "SELECT recommendation.resource_name, " .
  "recommendation.campaign, recommendation.keyword_recommendation " .
  "FROM recommendation " .
  "WHERE recommendation.type = KEYWORD";

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

my $search_stream_handler =
  Google::Ads::GoogleAds::Utils::SearchStreamHandler->new({
    service => $google_ads_service,
    request => {
      customerId => $customer_id,
      query      => $search_query
    }});

# Create apply operations for all the recommendations found.
my $apply_recommendation_operations = ();
$search_stream_handler->process_contents(
  sub {
    my $google_ads_row = shift;
    my $recommendation = $google_ads_row->{recommendation};
    printf "Keyword recommendation '%s' was found for campaign '%s'.\n",
      $recommendation->{resourceName}, $recommendation->{campaign};
    my $keyword = $recommendation->{keywordRecommendation}{keyword};
    printf "\tKeyword = '%s'\n",    $keyword->{text};
    printf "\tMatch type = '%s'\n", $keyword->{matchType};
    # Creates an ApplyRecommendationOperation that will apply this recommendation, and adds
    # it to the list of operations.
    push @$apply_recommendation_operations,
      build_recommendation_operation($recommendation);
  });
      

curl

# Gets keyword recommendations.
#
# Variables:
#   API_VERSION,
#   CUSTOMER_ID,
#   DEVELOPER_TOKEN,
#   MANAGER_CUSTOMER_ID,
#   OAUTH2_ACCESS_TOKEN:
#     See https://developers.google.com/google-ads/api/rest/auth#request_headers
#     for details.
curl -f --request POST \
"https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/googleAds:search" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data @- <<EOF
{
"query": "
  SELECT
    recommendation.campaign,
    recommendation.keyword_recommendation
  FROM recommendation
  WHERE
    recommendation.type = KEYWORD
"
}
EOF
      

採取行動

您可以套用或略過任何擷取的最佳化建議。

視建議類型而定,建議可能會每天變更,甚至一天變更多次。發生這種情況時,建議物件的 resource_name 可能會在擷取建議後過時。

建議您在擷取建議後不久就採取行動。

套用最佳化建議

影片:套用最佳化建議

您可以使用 RecommendationServiceApplyRecommendation 方法,套用有效或已略過的建議。

建議類型可能會有必要或選用參數。大多數最佳化建議都會提供建議值,且預設會使用這些值。

並非所有最佳化建議類型都支援自動套用最佳化建議的帳戶設定。不過,您可以針對 Google Ads API 完全支援的最佳化建議類型,實作類似行為。詳情請參閱DetectAndApplyRecommendations程式碼範例

使用 ApplyRecommendationOperationapply_parameters 聯集欄位,套用具有特定參數值的建議。每種適用的最佳化建議類型都有專屬欄位。 如果 apply_parameters 欄位中未列出任何建議類型,就不會使用這些參數值。

程式碼範例

下列程式碼示範如何建構 ApplyRecommendationOperation,以及如何覆寫建議值 (如要換成自己的值)。

Java

/** Creates and returns an ApplyRecommendationOperation to apply the given recommendation. */
private ApplyRecommendationOperation buildRecommendationOperation(Recommendation recommendation) {
  // If you have a recommendation ID instead of a resource name, you can create a resource name
  // like this:
  // String resourceName = ResourceNames.recommendation(customerId, recommendationId);

  // Creates a builder to construct the operation.
  Builder operationBuilder = ApplyRecommendationOperation.newBuilder();

  // Each recommendation type has optional parameters to override the recommended values. Below is
  // an example showing how to override a recommended ad when a TextAdRecommendation is applied.
  // operationBuilder.getTextAdBuilder().getAdBuilder().setResourceName("INSERT_AD_RESOURCE_NAME");

  // Sets the operation's resource name to the resource name of the recommendation to apply.
  operationBuilder.setResourceName(recommendation.getResourceName());
  return operationBuilder.build();
}
      

C#

private ApplyRecommendationOperation BuildApplyRecommendationOperation(
    string recommendationResourceName
)
{
    // If you have a recommendation_id instead of the resource_name you can create a
    // resource name from it like this:
    // string recommendationResourceName =
    //    ResourceNames.Recommendation(customerId, recommendationId)

    // 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.
    /*
    Ad overridingAd = new Ad()
    {
        Id = "INSERT_AD_ID_AS_LONG_HERE"
    };
    applyRecommendationOperation.TextAd = new TextAdParameters()
    {
        Ad = overridingAd
    };
    */

    ApplyRecommendationOperation applyRecommendationOperation =
    new ApplyRecommendationOperation()
    {
        ResourceName = recommendationResourceName
    };

    return applyRecommendationOperation;
}
      

PHP

private static function buildRecommendationOperation(
    string $recommendationResourceName
): ApplyRecommendationOperation {
    // If you have a recommendation_id instead of the resource name, you can create a resource
    // name from it like this:
    /*
    $recommendationResourceName =
        ResourceNames::forRecommendation($customerId, $recommendationId);
    */

    // 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.
    $applyRecommendationOperation = new ApplyRecommendationOperation();
    $applyRecommendationOperation->setResourceName($recommendationResourceName);
    return $applyRecommendationOperation;
}
      

Python

def build_recommendation_operation(client, recommendation):
    """Creates a ApplyRecommendationOperation to apply the given recommendation.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        recommendation: a resource name for the recommendation to be applied.
    """
    # If you have a recommendation ID instead of a resource name, you can create
    # a resource name like this:
    #
    # googleads_service = client.get_service("GoogleAdsService")
    # resource_name = googleads_service.recommendation_path(
    #   customer_id, recommendation.id
    # )

    operation = client.get_type("ApplyRecommendationOperation")

    # Each recommendation type has optional parameters to override the
    # recommended values. Below is an example showing how to override a
    # recommended ad when a TextAdRecommendation is applied.
    #
    # operation.text_ad.ad.resource_name = "INSERT_AD_RESOURCE_NAME"
    #
    # For more details, see:
    # https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation#apply_parameters

    operation.resource_name = recommendation
    return operation
      

小茹

def build_recommendation_operation(client, recommendation)
  # If you have a recommendation_id instead of the resource_name
  # you can create a resource name from it like this:
  # recommendation_resource =
  #    client.path.recommendation(customer_id, recommendation_id)

  operations = client.operation.apply_recommendation
  operations.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.
  #
  # 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
  # operation.text_ad = text_ad_parameters
  #
  # For more details, see:
  # https://developers.google.com/google-ads/api/reference/rpc/latest/ApplyRecommendationOperation#apply_parameters

  return operation
end
      

Perl

sub build_recommendation_operation {
  my ($recommendation) = @_;

  # If you have a recommendation ID instead of a resource name, you can create a resource
  # name like this:
  # my $recommendation_resource_name =
  #   Google::Ads::GoogleAds::V20::Utils::ResourceNames::recommendation(
  #   $customer_id, $recommendation_id);

  # Each recommendation type has optional parameters to override the recommended values.
  # Below is an example showing how to override a recommended ad when a TextAdRecommendation
  # is applied.
  # my $overriding_ad = Google::Ads::GoogleAds::V20::Resources::Ad->new({
  #   id => "INSERT_AD_ID_AS_INTEGER_HERE"
  # });
  # my $text_ad_parameters =
  #   Google::Ads::GoogleAds::V20::Services::RecommendationService::TextAdParameters
  #   ->new({ad => $overriding_ad});
  # $apply_recommendation_operation->{textAd} = $text_ad_parameters;

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

  return $apply_recommendation_operation;
}
      

下一個範例會呼叫 ApplyRecommendation,傳送在上一個程式碼中建立的套用建議作業。

Java

// Issues a mutate request to apply the recommendations.
ApplyRecommendationResponse applyRecommendationsResponse =
    recommendationServiceClient.applyRecommendation(
        Long.toString(customerId), applyRecommendationOperations);
for (ApplyRecommendationResult applyRecommendationResult :
    applyRecommendationsResponse.getResultsList()) {
  System.out.printf(
      "Applied recommendation with resource name: '%s'.%n",
      applyRecommendationResult.getResourceName());
}
      

C#

private void ApplyRecommendation(GoogleAdsClient client, long customerId,
    List<ApplyRecommendationOperation> operations)
{
    // Get the RecommendationServiceClient.
    RecommendationServiceClient recommendationService = client.GetService(
        Services.V20.RecommendationService);

    ApplyRecommendationRequest applyRecommendationRequest = new ApplyRecommendationRequest()
    {
        CustomerId = customerId.ToString(),
    };

    applyRecommendationRequest.Operations.AddRange(operations);

    ApplyRecommendationResponse response =
        recommendationService.ApplyRecommendation(applyRecommendationRequest);
    foreach (ApplyRecommendationResult result in response.Results)
    {
        Console.WriteLine("Applied a recommendation with resource name: " +
            result.ResourceName);
    }
}
      

PHP

private static function applyRecommendations(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    array $operations
): void {
    // Issues a mutate request to apply the recommendations.
    $recommendationServiceClient = $googleAdsClient->getRecommendationServiceClient();
    $response = $recommendationServiceClient->applyRecommendation(
        ApplyRecommendationRequest::build($customerId, $operations)
    );
    foreach ($response->getResults() as $appliedRecommendation) {
        /** @var Recommendation $appliedRecommendation */
        printf(
            "Applied a recommendation with resource name: '%s'.%s",
            $appliedRecommendation->getResourceName(),
            PHP_EOL
        );
    }
}
      

Python

def apply_recommendations(client, customer_id, operations):
    """Applies a batch of recommendations.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        operations: a list of ApplyRecommendationOperation messages.
    """
    # Issues a mutate request to apply the recommendations.
    recommendation_service = client.get_service("RecommendationService")
    response = recommendation_service.apply_recommendation(
        customer_id=customer_id, operations=operations
    )

    for result in response.results:
        print(
            "Applied a recommendation with resource name: "
            f"'{result[0].resource_name}'."
        )
      

小茹

def apply_recommendations(client, customer_id, operations)
  # Issues a mutate request to apply the recommendation.
  recommendation_service = client.service.recommendation

  response = recommendation_service.apply_recommendation(
    customer_id: customer_id,
    operations: [operations],
  )

  response.results.each do |applied_recommendation|
    puts "Applied recommendation with resource name: '#{applied_recommendation.resource_name}'."
  end
end
      

Perl

# Issue a mutate request to apply the recommendations.
my $apply_recommendation_response =
  $api_client->RecommendationService()->apply({
    customerId => $customer_id,
    operations => $apply_recommendation_operations
  });

foreach my $result (@{$apply_recommendation_response->{results}}) {
  printf "Applied recommendation with resource name: '%s'.\n",
    $result->{resourceName};
}
      

curl

# Applies a recommendation.
#
# Variables:
#   API_VERSION,
#   CUSTOMER_ID,
#   DEVELOPER_TOKEN,
#   MANAGER_CUSTOMER_ID,
#   OAUTH2_ACCESS_TOKEN:
#     See https://developers.google.com/google-ads/api/rest/auth#request_headers
#     for details.
#
#   RECOMMENDATION_RESOURCE_NAME: The resource name of the recommendation to
#     apply, from the previous request.
curl -f --request POST \
"https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/recommendations:apply" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data @- <<EOF
{
  "operations": [
    {
      "resourceName": "${RECOMMENDATION_RESOURCE_NAME}"
    }
  ]
}
EOF
      

觀看這些影片瞭解詳情

套用參數

大量

錯誤

測試命名空間

關閉建議

影片:關閉最佳化建議

您可以使用 RecommendationService 關閉建議。程式碼結構與套用最佳化建議類似,但您會改用 DismissRecommendationOperationRecommendationService.DismissRecommendation

觀看這些影片瞭解詳情

大量

錯誤

測試命名空間

自動套用建議

您可以透過 RecommendationSubscriptionService 自動套用特定類型的最佳化建議。

如要訂閱特定類型的最佳化建議,請建立 RecommendationSubscription 物件,將 type 欄位設為其中一個支援的最佳化建議類型,並將 status 欄位設為 ENABLED

支援訂閱的建議類型

  • ENHANCED_CPC_OPT_IN
  • KEYWORD
  • KEYWORD_MATCH_TYPE
  • LOWER_TARGET_ROAS
  • MAXIMIZE_CLICKS_OPT_IN
  • OPTIMIZE_AD_ROTATION
  • RAISE_TARGET_CPA
  • RESPONSIVE_SEARCH_AD
  • RESPONSIVE_SEARCH_AD_IMPROVE_AD_STRENGTH
  • SEARCH_PARTNERS_OPT_IN
  • SEARCH_PLUS_OPT_IN
  • SET_TARGET_CPA
  • SET_TARGET_ROAS
  • TARGET_CPA_OPT_IN
  • TARGET_ROAS_OPT_IN
  • USE_BROAD_MATCH_KEYWORD

擷取訂閱項目

如要取得帳戶的建議訂閱項目相關資訊,請查詢 recommendation_subscription 資源。

如要查看自動套用的變更,請查詢 change_event 資源,並將 change_event.client_type 篩選器設為 GOOGLE_ADS_RECOMMENDATIONS_SUBSCRIPTION

建立廣告活動時的最佳化建議

您可以在建立廣告活動時,使用 RecommendationService.GenerateRecommendationsRequest ,針對特定類型的最佳化建議產生建議。

GenerateRecommendations 接受的輸入內容包括顧客 ID、廣告管道類型 (必須是 SEARCHPERFORMANCE_MAX)、要產生的建議類型清單,以及取決於指定類型的各種資料點。根據您提供的資料,輸出 Recommendation 物件清單。如果資料不足,無法為要求的recommendation_types產生建議,或廣告活動已處於建議狀態,結果集就不會包含該類型的建議。請確保應用程式能處理要求的建議類型未傳回任何建議的情況。

下表說明 GenerateRecommendations 支援的建議類型,以及您必須提供的欄位,才能取得該類型的建議。最佳做法是收集完所有與所要求建議類型相關的資訊後,再傳送 GenerateRecommendations 要求。如要進一步瞭解必填和選填欄位 (包括巢狀欄位),請參閱參考說明文件

RecommendationType 必填欄位 選填欄位
CAMPAIGN_BUDGET (自第 18 版起) 搜尋和最高成效廣告活動都必須填寫下列欄位:
  • asset_group_info
  • final_url
  • bidding_strategy_type
如果是搜尋廣告活動,還必須填寫下列欄位:
  • country_code
  • language_code
  • positive_location_idnegative_location_id
  • ad_group_info.keywords
  • bidding_info.
    bidding_strategy_target_info.
    target_impression_share_info
    如果出價策略設為 TARGET_IMPRESSION_SHARE
  • budget_info
  • 如果是最高成效廣告活動,請在 merchant_center_account_id 欄位中提供值,向 RecommendationsService 指出要為零售業專用最高成效廣告活動 (而非標準最高成效廣告活動) 產生最佳化建議。
KEYWORD
  • seed_info
  • ad_group_info
MAXIMIZE_CLICKS_OPT_IN
  • conversion_tracking_status
  • bidding_info
MAXIMIZE_CONVERSIONS_OPT_IN
  • conversion_tracking_status
  • bidding_info
MAXIMIZE_CONVERSION_VALUE_OPT_IN
  • conversion_tracking_status
  • bidding_info
SET_TARGET_CPA
  • conversion_tracking_status
  • bidding_info
SET_TARGET_ROAS
  • conversion_tracking_status
  • bidding_info
SITELINK_ASSET
注意:傳回的 SitelinkAssetRecommendation 物件會包含空白清單。如果回應包含 GenerateRecommendations SitelinkAssetRecommendation,則可視為信號,在廣告活動中新增至少一個網站連結素材資源。
  • campaign_sitelink_count
TARGET_CPA_OPT_IN
  • conversion_tracking_status
  • bidding_info
TARGET_ROAS_OPT_IN
  • conversion_tracking_status
  • bidding_info

使用流程範例

假設貴公司是廣告代理商,為使用者提供廣告活動建構工作流程,並希望在該流程中為使用者提供建議。您可以透過 GenerateRecommendationsRequest 視需要產生建議,並將這些建議納入廣告活動製作使用者介面。

使用流程可能如下所示:

  1. 使用者前往您的應用程式建立最高成效廣告活動。

  2. 使用者會在廣告活動建構流程中提供一些初始資訊。舉例來說,他們提供詳細資料來建立單一SitelinkAsset,並選取TARGET_SPEND做為智慧出價策略。

  3. 您會傳送 GenerateRecommendationsRequest,並設定下列欄位:

    • campaign_sitelink_count:設為 1,也就是進行中廣告活動的網站連結素材資源數量。

    • bidding_info:將巢狀 bidding_strategy_type 欄位設為 TARGET_SPEND

    • conversion_tracking_status:設為這個顧客的ConversionTrackingStatus。如需如何擷取這個欄位的指引,請參閱轉換管理入門指南

    • recommendation_types:設為 [SITELINK_ASSET, MAXIMIZE_CLICKS_OPT_IN]

    • advertising_channel_type:設為 PERFORMANCE_MAX

    • customer_id:設為建立廣告活動的客戶 ID。

  4. 您可以採用 GenerateRecommendationsResponse 中的建議 (在本例中為 SitelinkAssetRecommendationMaximizeClicksOptInRecommendation),並在廣告活動建構介面中顯示這些建議,供使用者參考。如果使用者接受建議,您可以在使用者完成廣告活動建構流程後,將建議納入廣告活動建立要求。