在 Google Ads 中,轉換是指使用者與廣告互動後,採取的有價值動作,例如購買產品、提交待開發客戶表單、致電商家或親臨實體商店。轉換追蹤會評估這些顧客互動,方便您評估廣告活動成效,並調整自動出價。
您可以使用 Google Ads API,以程式輔助方式設定轉換動作、匯入離線轉換事件、強化或調整記錄的轉換、將動作分組為出價和生命週期目標,以及監控上傳診斷。
選擇轉換工作流程
請參閱下表,找出適合您用途的 ConversionActionType、API 服務和導入指南:
端對端轉換生命週期
在 Google Ads API 中,完整的轉換管理整合程序分為四個階段:
- 驗證帳戶設定並建立轉換動作:查詢
Customer.conversion_tracking_setting,確認有效的轉換帳戶 (google_ads_conversion_customer)、驗證轉換追蹤功能是否有效、設定使用者同意聲明,並建立ConversionAction,指定ConversionActionType和ConversionActionCategory。 - 匯入轉換事件:使用
ConversionUploadService串流離線點擊或來電轉換,並將partial_failure設為true;使用ConversionAdjustmentUploadService進行ENHANCEMENT調整,補充網站轉換資料;或使用OfflineUserDataJobService批次上傳商店銷售資料。 - 調整及最佳化轉換:使用
ConversionAdjustmentUploadService撤銷或重編記錄的轉換、附加ConversionCustomVariable中繼資料、套用轉換價值規則,以及將動作整理成轉換目標和生命週期目標,以控管出價最佳化。 - 監控診斷資料和報表成效:查詢
offline_conversion_upload_client_summary和offline_conversion_upload_conversion_action_summary,檢查上傳處理狀態和部分失敗警示。查詢customer或campaign資源 (可選擇依segments.conversion_action區隔),比較metrics.conversions和metrics.all_conversions指標,或查詢conversion_action資源,檢查metrics.all_conversions和上次轉換時間戳記。
快速入門導覽課程:驗證設定、建立動作及檢查健康狀態
以下範例說明初始化及監控轉換追蹤時,最常使用的三種查詢和異動。
1. 使用 GAQL 驗證轉換追蹤設定
建立 ConversionAction 或上傳事件前,請使用 GoogleAdsService.SearchStream 查詢 customer 資源,判斷哪個帳戶管理轉換 (google_ads_conversion_customer)、是否已接受客戶資料條款,以及是否已啟用帳戶層級強化轉換 (EnhancedConversionsConfig):
SELECT
customer.conversion_tracking_setting.conversion_tracking_id,
customer.conversion_tracking_setting.conversion_tracking_status,
customer.conversion_tracking_setting.cross_account_conversion_tracking_id,
customer.conversion_tracking_setting.google_ads_conversion_customer,
customer.conversion_tracking_setting.accepted_customer_data_terms,
customer.conversion_tracking_setting.enablement_setting,
customer.conversion_tracking_setting.effective_enablement_setting
FROM customer
從 google_ads_conversion_customer 傳回的 customers/{customer_id} 資源名稱中擷取 {customer_id},並針對該客戶 ID 發出所有後續的 ConversionActionService 和 ConversionUploadService 要求。如需完整設定和跨帳戶階層詳細資料,請參閱「入門指南」。
2. 建立轉換動作
使用 ConversionActionService.MutateConversionActions 建立 ConversionAction。以下範例會建立 UPLOAD_CLICKS 轉換動作,並設定自訂價值和回溯期:
Java
private void runExample(GoogleAdsClient googleAdsClient, long customerId) { // Creates a ConversionAction. ConversionAction conversionAction = ConversionAction.newBuilder() // Note that conversion action names must be unique. If a conversion action already // exists with the specified conversion_action_name the create operation will fail with // a ConversionActionError.DUPLICATE_NAME error. .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime()) .setCategory(ConversionActionCategory.DEFAULT) .setType(ConversionActionType.WEBPAGE) .setStatus(ConversionActionStatus.ENABLED) .setViewThroughLookbackWindowDays(15L) .setValueSettings( ValueSettings.newBuilder() .setDefaultValue(23.41) .setAlwaysUseDefaultValue(true) .build()) .build(); // Creates the operation. ConversionActionOperation operation = ConversionActionOperation.newBuilder().setCreate(conversionAction).build(); try (ConversionActionServiceClient conversionActionServiceClient = googleAdsClient.getLatestVersion().createConversionActionServiceClient()) { MutateConversionActionsResponse response = conversionActionServiceClient.mutateConversionActions( Long.toString(customerId), Collections.singletonList(operation)); System.out.printf("Added %d conversion actions:%n", response.getResultsCount()); for (MutateConversionActionResult result : response.getResultsList()) { System.out.printf( "New conversion action added with resource name: '%s'%n", result.getResourceName()); } } }
C#
public void Run(GoogleAdsClient client, long customerId) { // Get the ConversionActionService. ConversionActionServiceClient conversionActionService = client.GetService(Services.V26.ConversionActionService); // Note that conversion action names must be unique. // If a conversion action already exists with the specified name the create operation // will fail with a ConversionAction.DUPLICATE_NAME error. string ConversionActionName = "Earth to Mars Cruises Conversion #" + ExampleUtilities.GetRandomString(); // Add a conversion action. ConversionAction conversionAction = new ConversionAction() { Name = ConversionActionName, Category = ConversionActionCategory.Default, Type = ConversionActionType.Webpage, Status = ConversionActionStatus.Enabled, ViewThroughLookbackWindowDays = 15, ValueSettings = new ConversionAction.Types.ValueSettings() { DefaultValue = 23.41, AlwaysUseDefaultValue = true } }; // Create the operation. ConversionActionOperation operation = new ConversionActionOperation() { Create = conversionAction }; try { // Create the conversion action. MutateConversionActionsResponse response = conversionActionService.MutateConversionActions(customerId.ToString(), new ConversionActionOperation[] { operation }); // Display the results. foreach (MutateConversionActionResult newConversionAction in response.Results) { Console.WriteLine($"New conversion action with resource name = " + $"'{newConversionAction.ResourceName}' was added."); } } 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) { // Creates a conversion action. $conversionAction = new ConversionAction( [ // Note that conversion action names must be unique. // If a conversion action already exists with the specified conversion_action_name // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error. 'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(), 'category' => ConversionActionCategory::PBDEFAULT, 'type' => ConversionActionType::WEBPAGE, 'status' => ConversionActionStatus::ENABLED, 'view_through_lookback_window_days' => 15, 'value_settings' => new ValueSettings( [ 'default_value' => 23.41, 'always_use_default_value' => true ] ) ] ); // Creates a conversion action operation. $conversionActionOperation = new ConversionActionOperation(); $conversionActionOperation->setCreate($conversionAction); // Issues a mutate request to add the conversion action. $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient(); $response = $conversionActionServiceClient->mutateConversionActions( MutateConversionActionsRequest::build($customerId, [$conversionActionOperation]) ); printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL); foreach ($response->getResults() as $addedConversionAction) { /** * @var ConversionAction $addedConversionAction */ printf( "New conversion action added with resource name: '%s'%s", $addedConversionAction->getResourceName(), PHP_EOL ); } }
Python
def main(client: GoogleAdsClient, customer_id: str) -> None: conversion_action_service: ConversionActionServiceClient = ( client.get_service("ConversionActionService") ) # Create the operation. conversion_action_operation: ConversionActionOperation = client.get_type( "ConversionActionOperation" ) # Create conversion action. conversion_action: ConversionAction = conversion_action_operation.create # Note that conversion action names must be unique. If a conversion action # already exists with the specified conversion_action_name, the create # operation will fail with a ConversionActionError.DUPLICATE_NAME error. conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}" conversion_action.type_ = ( client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS ) conversion_action.category = ( client.enums.ConversionActionCategoryEnum.DEFAULT ) conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED conversion_action.view_through_lookback_window_days = 15 # Create a value settings object. value_settings: ConversionAction.ValueSettings = ( conversion_action.value_settings ) value_settings.default_value = 15.0 value_settings.always_use_default_value = True # Add the conversion action. conversion_action_response: MutateConversionActionsResponse = ( conversion_action_service.mutate_conversion_actions( customer_id=customer_id, operations=[conversion_action_operation], ) ) print( "Created conversion action " f'"{conversion_action_response.results[0].resource_name}".' )
小茹
def add_conversion_action(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 # Add a conversion action. conversion_action = client.resource.conversion_action do |ca| ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}" ca.type = :UPLOAD_CLICKS ca.category = :DEFAULT ca.status = :ENABLED ca.view_through_lookback_window_days = 15 # Create a value settings object. ca.value_settings = client.resource.value_settings do |vs| vs.default_value = 15 vs.always_use_default_value = true end end # Create the operation. conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action) # Add the ad group ad. response = client.service.conversion_action.mutate_conversion_actions( customer_id: customer_id, operations: [conversion_action_operation], ) puts "New conversion action with resource name = #{response.results.first.resource_name}." end
Perl
sub add_conversion_action { my ($api_client, $customer_id) = @_; # Note that conversion action names must be unique. # If a conversion action already exists with the specified conversion_action_name, # the create operation fails with error ConversionActionError.DUPLICATE_NAME. my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid(); # Create a conversion action. my $conversion_action = Google::Ads::GoogleAds::V26::Resources::ConversionAction->new({ name => $conversion_action_name, category => DEFAULT, type => WEBPAGE, status => ENABLED, viewThroughLookbackWindowDays => 15, valueSettings => Google::Ads::GoogleAds::V26::Resources::ValueSettings->new({ defaultValue => 23.41, alwaysUseDefaultValue => "true" })}); # Create a conversion action operation. my $conversion_action_operation = Google::Ads::GoogleAds::V26::Services::ConversionActionService::ConversionActionOperation ->new({create => $conversion_action}); # Add the conversion action. my $conversion_actions_response = $api_client->ConversionActionService()->mutate({ customerId => $customer_id, operations => [$conversion_action_operation]}); printf "New conversion action added with resource name: '%s'.\n", $conversion_actions_response->{results}[0]{resourceName}; return 1; }
curl
REST 要求
如要透過 REST 建立相同的 ConversionAction,請將 POST 要求傳送至 ConversionActionService.MutateConversionActions:
POST https://googleads.googleapis.com/v26/customers/{customer_id}/conversionActions:mutate
{
"operations": [
{
"create": {
"name": "Earth to Mars Cruise Conversion",
"type": "UPLOAD_CLICKS",
"category": "DEFAULT",
"status": "ENABLED",
"primaryForGoal": true,
"countingType": "ONE_PER_CLICK",
"clickThroughLookbackWindowDays": "60",
"valueSettings": {
"defaultValue": 23.41,
"defaultCurrencyCode": "USD",
"alwaysUseDefaultValue": true
}
}
}
]
}
轉換動作ENABLED後,請使用轉換來源的工作流程匯入轉換事件或強化資料 (請參閱「匯入轉換事件」)。
3. 監控離線轉換上傳健康狀態
上傳點擊轉換、來電轉換或轉換調整項後,請查詢 offline_conversion_upload_client_summary,查看最近上傳項目的整體工作狀態、成功率和待處理率,以及錯誤細目:
SELECT
offline_conversion_upload_client_summary.client,
offline_conversion_upload_client_summary.status,
offline_conversion_upload_client_summary.total_event_count,
offline_conversion_upload_client_summary.successful_event_count,
offline_conversion_upload_client_summary.success_rate,
offline_conversion_upload_client_summary.pending_event_count,
offline_conversion_upload_client_summary.pending_rate,
offline_conversion_upload_client_summary.last_upload_date_time,
offline_conversion_upload_client_summary.alerts
FROM offline_conversion_upload_client_summary
查詢 offline_conversion_upload_conversion_action_summary,取得轉換動作層級的診斷資料 (請參閱「監控離線資料診斷」),並參閱「排解轉換匯入問題」一文,瞭解如何解決特定錯誤代碼。
指南目錄 (依生命週期階段)
瀏覽依生命週期階段分類的完整轉換管理指南:
1. 帳戶設定和轉換動作
- 轉換動作類別:選取正確的轉換來源,包括網站 (
WEBPAGE)、來電 (UPLOAD_CALLS、AD_CALL、WEBSITE_CALL)、行動應用程式 (GOOGLE_PLAY_DOWNLOAD、GOOGLE_PLAY_IN_APP_PURCHASE、Firebase、SKAdNetwork)、Google Analytics 4 (GOOGLE_ANALYTICS_4_CUSTOM、GOOGLE_ANALYTICS_4_PURCHASE)、離線 (UPLOAD_CLICKS) 或實體商店 (STORE_SALES),然後對應至相應的ConversionActionType和 API 工作流程。 - 入門指南:設定使用者同意聲明、驗證
ConversionTrackingSetting、設定跨帳戶轉換追蹤,以及使用用戶端程式庫或 REST 建立轉換動作。
2. 匯入轉換事件
- 匯入離線點擊轉換:上傳離線轉換 (
GCLID、GBRAID、WBRAID) 和待開發客戶強化轉換 (第一方雜湊電子郵件和電話號碼),評估實際交易。 - 匯入線上點擊轉換:使用網站強化轉換 (
ENHANCEMENT調整項),以第一方使用者資料 (例如電子郵件地址、姓名、住家地址和電話號碼) 補充網站轉換代碼。 - 匯入來電轉換:上傳透過 Google 轉接號碼或您自己的通話追蹤系統追蹤的來電轉換事件。
- 匯入商店銷售轉換:使用
OfflineUserDataJobService批次上傳商店交易資料。
3. 調整及最佳化轉換
- 匯入後調整轉換:針對
UPLOAD_CLICKS、WEBPAGE和SALESFORCE(已淘汰) 轉換動作,撤銷已取消的訂單 (RETRACTION) 或重編修改後的轉換價值 (RESTATEMENT)。 - 管理轉換價值規則:在競價期間,根據目標對象、裝置、地理位置或行程條件,動態調整轉換價值。
- 自訂轉換變數:定義自訂鍵/值代碼 (
ConversionCustomVariable),並附加至點擊、來電和網站轉換,以便產生區隔報表。 - 轉換目標:依
category(ConversionActionCategory) 和origin(ConversionOrigin) 欄位將轉換動作分組,並設定顧客目標、廣告活動和自訂目標,以及顧客生命週期目標 (獲取新客、顧客留存率和忠誠度留存率)。您也可以擷取並套用OPTIMIZE_FOR_NEW_CUSTOMERS最佳化建議,提高新客轉換價值。
4. 監控、回報及疑難排解
- 監控離線資料診斷:在帳戶層級 (
offline_conversion_upload_client_summary) 和轉換動作層級 (offline_conversion_upload_conversion_action_summary) 查詢離線資料診斷,追蹤成功率、待處理事件和上傳快訊。 - 擷取轉換統計資料:在 GAQL 中查詢轉換成效指標,並將 Google Ads UI 欄對應至 Google Ads API 欄位。
- 疑難排解轉換匯入問題:診斷並解決常見的
ConversionUploadError和ConversionAdjustmentUploadError程式碼問題。