您必须在 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.V25.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 ); } }