您必须在 Google Ads 转化账号中启用转化跟踪,才能记录转化。本指南详细介绍了如何确认是否已启用转化跟踪,如果尚未启用,则如何启用转化跟踪,以及如何检索有关现有转化操作的信息。
对于大多数转化操作,您还需要执行额外的操作才能进行跟踪。如需详细了解各种转化操作类型及其 要求,请参阅创建转化操作指南。
准备提供用户意见征求
务必确认您有权与 Google 分享转化数据。这可以通过以下两种方法完成:
- 配置账号级默认用户意见征求设置。在 Google Ads 界面中,依次点击 工具 -> 数据管理器 -> 用户意见征求设置 -> 默认用户意见征求设置。
- 在每项导入的转化中设置 ClickConversion.consent 字段。
设置网站以跟踪转化
如果您要开始集成线下转化数据导入功能,第一步是 按照 为增强型潜在客户转化配置 Google 代码 指南中的步骤,将网站配置为跟踪增强型潜在客户转化。您还可以按照 为增强型潜在客户转化配置 Google 跟踪代码管理器 指南中的步骤,使用 Google 跟踪代码管理器来配置网站。
在 Google Ads 转化账号中启用转化跟踪
检索有关转化跟踪设置的信息
您可以查询 Customer 资源的 ConversionTrackingSetting,以检查账号的转化跟踪设置并确认是否已启用转化跟踪。使用
GoogleAdsService.SearchStream发出以下查询:
SELECT
customer.conversion_tracking_setting.google_ads_conversion_customer,
customer.conversion_tracking_setting.conversion_tracking_status,
customer.conversion_tracking_setting.conversion_tracking_id,
customer.conversion_tracking_setting.cross_account_conversion_tracking_id
FROM customer
google_ads_conversion_customer 字段表示为该客户创建和管理转化的 Google Ads 账号。对于使用
跨账号转化跟踪的客户,这是经理账号的 ID。在 Google Ads API 请求中,应将 Google Ads 转化客户 ID 作为 customer_id 提供,以创建和管理转化。
请注意,即使未启用转化跟踪,系统也会填充此字段。
The
conversion_tracking_status
字段表示是否已启用转化跟踪,以及账号
是否在使用跨账号转化跟踪。
在 Google Ads 转化客户下创建转化操作
如果 conversion_tracking_status 值为 NOT_CONVERSION_TRACKED,则表示该账号未启用转化跟踪。若要启用转化跟踪
,请在 Google Ads 转化账号中创建至少一个 ConversionAction,如以下示例所示。或者,您
也可以按照要启用的
转化类型的
帮助中心中的说明,在界面中创建转化操作。
请注意,通过 Google Ads API 发送时,系统会自动启用增强型转化,但可以通过 Google Ads 界面停用增强型转化。
代码示例
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.V24.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}".' )
Ruby
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::V24::Resources::ConversionAction->new({ name => $conversion_action_name, category => DEFAULT, type => WEBPAGE, status => ENABLED, viewThroughLookbackWindowDays => 15, valueSettings => Google::Ads::GoogleAds::V24::Resources::ValueSettings->new({ defaultValue => 23.41, alwaysUseDefaultValue => "true" })}); # Create a conversion action operation. my $conversion_action_operation = Google::Ads::GoogleAds::V24::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
确保 conversion_action_type 设置为正确的
ConversionActionType 值。
如需详细了解如何在 Google Ads API 中创建转化操作,请参阅创建转化操作。
检索现有转化操作
您可以通过发出以下查询来检索现有转化操作的详细信息。确保请求中的客户 ID 设置为您在上面确定的 Google Ads
转化客户,并且转化操作类型设置
为正确的
ConversionActionType
值。
SELECT
conversion_action.resource_name,
conversion_action.name,
conversion_action.status
FROM conversion_action
WHERE conversion_action.type = 'INSERT_CONVERSION_ACTION_TYPE'
跨账号转化跟踪
如果您使用的是 跨账号转化
跟踪,
ConversionActionService 将返回
以下转化操作:
- 由经理账号定义的、为跨账号转化跟踪账号所用的全部转化操作
- 客户已累计统计信息的所有转化操作,包括系统定义的操作以及经理所拥有的操作(即使该经理随后取消了关联)
- 客户在自己的账号中定义的所有操作
- 在关联的 Google Analytics 媒体资源中创建的 Analytics 转化。
这包括未导入到 Google Ads 的 Analytics 转化操作,
其状态为
HIDDEN。
您可以在创建客户账号时使用 Google Ads API 选择启用跨账号转化跟踪。
创建新的 Customer 时,请将
conversion_tracking_setting.google_ads_conversion_customer
设置为应代表客户账号管理转化操作的经理
账号的
资源名称。
此经理账号还必须是为新客户账号发出 create 请求的账号。
您可以在创建和更新客户账号时使用 Google Ads API 选择启用跨账号转化跟踪。
更新现有客户账号时,您可以通过设置
conversion_tracking_setting.google_ads_conversion_customer
字段来选择启用跨账号
转化跟踪。此字段应设置为应代表客户账号管理转化操作的经理账号的
资源名称。
此经理账号还必须是为客户账号发出 update 请求的账号。
注意:使用 Google Ads API 修改客户账号的跨账号转化跟踪设置是一项仅限许可名单的功能。如需使用此功能,请与您的客户经理联系。
当您选择启用跨账号转化跟踪,或为现有客户账号切换转化跟踪经理时,适用的注意事项与在界面中进行此更改时相同。具体而言:
- 客户账号将采用其新转化跟踪经理的默认转化价值规则和默认客户生命周期目标。
- 围绕特定转化操作优化的广告系列将改为使用转化经理账号的默认转化目标。如果您继续围绕特定转化操作优化,可能会产生不一致的行为,因为经理账号与客户账号的目标可能有所不同。请确保您的广告系列围绕正确的目标进行优化。
- 如果某个账号属于多个经理账号,则该账号只能使用一个经理账号的转化操作。如果未指定转化跟踪账号,该账号将默认使用自身作为转化跟踪账号。
创建转化操作
若要衡量转化次数,请为希望跟踪的
转化操作的
type设置
ConversionAction。例如,网上购买和致电需要不同的转化操作。
要在 API 中设置新的转化操作,最佳方法是使用下面的
“添加转化操作”代码示例。此示例会为您处理
所有后台身份验证任务,并帮助您逐步完成创建
a ConversionAction的过程。
对于大多数转化操作,您还需要执行额外的操作才能进行跟踪。例如,若要跟踪网站上的转化,您必须在网站上的转化 页面中添加一个名为代码 的代码段。如需详细了解其他 转化操作类型的要求,请参阅我们的 帮助中心文章。
代码示例
以下代码示例将引导您完成创建新转化操作的过程。具体而言,它会创建一个
type 设置为
UPLOAD_CLICKS 的转化操作。
它还会将 category
设置为 DEFAULT。
系统会应用以下默认设置:
Google Ads API 会自动设置
primary_for_goal字段 ,但您可以明确设置此字段,以控制转化操作与转化目标结合使用时对账号中的报告和出价的影响。Google Ads API 会自动将
counting_type设置为MANY_PER_CLICK。如需了解详情,请参阅 转化计数选项简介 。Google Ads API 会通过将
attribution_model_settings字段设置为GOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN值,将归因模型设置为以数据 为依据。AttributionModel如需详细了解归因模型,请参阅这篇帮助中心文章 。
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.V24.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}".' )
Ruby
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::V24::Resources::ConversionAction->new({ name => $conversion_action_name, category => DEFAULT, type => WEBPAGE, status => ENABLED, viewThroughLookbackWindowDays => 15, valueSettings => Google::Ads::GoogleAds::V24::Resources::ValueSettings->new({ defaultValue => 23.41, alwaysUseDefaultValue => "true" })}); # Create a conversion action operation. my $conversion_action_operation = Google::Ads::GoogleAds::V24::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
您可以在客户端库的再营销文件夹中 以及代码示例集合中找到此示例:添加转化操作代码 示例。
验证
Google Ads 和 Google Ads API 支持各种转化操作,因此某些
验证规则会因 type
而异。
到目前为止,创建转化操作时最常见的错误是
DUPLICATE_NAME。
请确保为每个转化操作使用唯一的名称。
以下是一些关于设置 ConversionAction 字段的提示:
- 所有枚举字段
- 尝试将任何枚举字段设置为
UNKNOWN会导致RequestError.INVALID_ENUM_VALUE错误。 app_id- “
app_id”属性是不可变的,只能在创建新的 应用转化时设置。 attribution_model_settings- 将其设置为已废弃的
选项
会导致
CANNOT_SET_RULE_BASED_ATTRIBUTION_MODELS错误。Google Ads 仅支持GOOGLE_ADS_LAST_CLICK和GOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN。 click_through_lookback_window_days将此属性设置为允许范围之外的值会导致
RangeError.TOO_LOW或RangeError.TOO_HIGH错误。对于
AD_CALL或WEBSITE_CALL转化操作,此属性必须在[1,60]范围内。对于大多数其他转化操作,允许的范围是[1,30]。include_in_conversions_metric在
create或update操作中设置此值会导致FieldError.IMMUTABLE_FIELD错误。请改为按照 转化目标指南中的说明设置primary_for_goal。phone_call_duration_seconds尝试在不适用于通话的转化操作中设置此属性会导致
FieldError.VALUE_MUST_BE_UNSET错误。typetype属性是不可变的,只能在创建新转化时设置。更新转化操作,使其
type等于UNKNOWN会导致MutateError.MUTATE_NOT_ALLOWED错误。value_settings对于
WEBSITE_CALL或AD_CALL转化操作,value_settings必须将always_use_default_value设置为true。在创建或更新此值时指定false值会导致INVALID_VALUE错误。view_through_lookback_window_days将此属性设置为允许范围之外的值会导致
RangeError.TOO_LOW或RangeError.TOO_HIGH错误。对于大多数转化操作,允许的范围是[1,30]。无法在
AD_CALL或WEBSITE_CALL转化操作中设置此属性。指定值会导致VALUE_MUST_BE_UNSET错误。