管理在线点击转化

您可以使用 Google Ads API 管理 Google Ads 中的在线点击转化。在线点击转化有助于您跟踪促成在线销售(例如通过网站)的广告。

线上转化通过 Google 代码进行跟踪,但您可以使用 Google Ads API 对其进行调整或增强。

如果您已设置 Google 代码,并想调整在线转化,请参阅转化调整页面。 如果您已设置 Google 代码,并希望使用用户提供的数据来增强在线转化跟踪效果(也称为增强型网站转化),请继续阅读。

增强型网站转化

以下部分介绍了如何增强在线点击转化,也称为增强型网站转化

增强型网站转化需要设置一个代码,以便在用户转化时自动将点击标识符(例如 GCLID)和订单 ID 发送到 Google Ads。您可以通过 Google 跟踪代码管理器Google 代码或 Google Ads API 设置增强型转化。 使用 Google Ads API 的优势在于,您可以在转化事件发生后的 24 小时内发送第一方转化数据,而不是在同一时间发送。这样一来,您就可以从各种来源(例如客户数据库或 CRM 系统)找到第一方数据。

增强型网站转化的运作方式

Google Ads API 中的增强型网站转化是对以下流程中第 3 步的补充。

该代码不会在用户转化时发送经过哈希处理的用户信息,而只会发送 GCLID 和订单 ID;您可以在稍后通过导入订单 ID 和经过哈希处理的数据来发送经过哈希处理的用户信息。如需详细了解增强型网站转化,请访问我们的帮助中心

增强型网站转化

前提条件

您必须先接受客户数据条款,然后才能使用增强型网站转化。您可以向 Google Ads 转化客户发出以下查询,以验证客户数据条款是否已被接受:

SELECT
  customer.id,
  customer.conversion_tracking_setting.accepted_customer_data_terms
FROM customer

如果 accepted_customer_data_termsfalse,请按照帮助中心内的说明完成此前提条件。

配置代码植入

您可以按照帮助中心中的说明为网站配置代码植入。建议您还向转化跟踪代码中添加交易 ID(订单 ID),以帮助进行转化匹配。

API 实现

以下是在 Google Ads API 中导入增强型网站转化的总体流程。

  1. 对用户提供的数据(例如电子邮件地址、电话号码和邮寄地址)进行规范化处理和哈希处理

  2. 使用经过标准化和哈希处理的用户提供的数据填充 ConversionAdjustment 对象

  3. ConversionAdjustment 对象导入到 ConversionAdjustmentUploadService

  4. 检查导入的内容

对用户提供的数据进行规范化和哈希处理

出于隐私保护方面的考虑,以下数据在导入之前必须使用 SHA-256 进行哈希处理:

  • 电子邮件地址
  • 电话号码
  • 名字
  • 姓氏
  • 街道地址

请勿对以下数据进行哈希处理

  • 国家/地区
  • 州/省级行政区
  • 城市
  • 邮编

为了使哈希结果实现标准化,在对其中某个值进行哈希处理之前,请执行以下操作:

  • 移除开头和结尾处的空格。
  • 将文字转换为小写形式。
  • 根据 E164 标准设置电话号码的格式。
  • 对于电子邮件地址:
    • 移除用户名(@ 符号之前)中的所有句点 (.)。例如,jane.doe@example.com 变为 janedoe@example.com
    • 移除用户名(@ 符号之前)中的加号 (+) 符号及其后面的所有字符。例如,janedoe+newsletter@example.com 会变为 janedoe@example.com

Java

private String normalizeAndHash(MessageDigest digest, String s, boolean trimIntermediateSpaces)
    throws UnsupportedEncodingException {
  // Normalizes by first converting all characters to lowercase, then trimming spaces.
  String normalized = s.toLowerCase();
  if (trimIntermediateSpaces) {
    // Removes leading, trailing, and intermediate spaces.
    normalized = normalized.replaceAll("\\s+", "");
  } else {
    // Removes only leading and trailing spaces.
    normalized = normalized.trim();
  }
  // Hashes the normalized string using the hashing algorithm.
  byte[] hash = digest.digest(normalized.getBytes("UTF-8"));
  StringBuilder result = new StringBuilder();
  for (byte b : hash) {
    result.append(String.format("%02x", b));
  }

  return result.toString();
}

/**
 * Returns the result of normalizing and hashing an email address. For this use case, Google Ads
 * requires removal of any '.' characters preceding {@code gmail.com} or {@code googlemail.com}.
 *
 * @param digest the digest to use to hash the normalized string.
 * @param emailAddress the email address to normalize and hash.
 */
private String normalizeAndHashEmailAddress(MessageDigest digest, String emailAddress)
    throws UnsupportedEncodingException {
  String normalizedEmail = emailAddress.toLowerCase();
  String[] emailParts = normalizedEmail.split("@");
  if (emailParts.length > 1 && emailParts[1].matches("^(gmail|googlemail)\\.com\\s*")) {
    // Removes any '.' characters from the portion of the email address before the domain if the
    // domain is gmail.com or googlemail.com.
    emailParts[0] = emailParts[0].replaceAll("\\.", "");
    normalizedEmail = String.format("%s@%s", emailParts[0], emailParts[1]);
  }
  return normalizeAndHash(digest, normalizedEmail, true);
}
      

C#

/// <summary>
/// Normalizes the email address and hashes it. For this use case, Google Ads requires
/// removal of any '.' characters preceding <code>gmail.com</code> or
/// <code>googlemail.com</code>.
/// </summary>
/// <param name="emailAddress">The email address.</param>
/// <returns>The hash code.</returns>
private string NormalizeAndHashEmailAddress(string emailAddress)
{
    string normalizedEmail = emailAddress.ToLower();
    string[] emailParts = normalizedEmail.Split('@');
    if (emailParts.Length > 1 && (emailParts[1] == "gmail.com" ||
        emailParts[1] == "googlemail.com"))
    {
        // Removes any '.' characters from the portion of the email address before
        // the domain if the domain is gmail.com or googlemail.com.
        emailParts[0] = emailParts[0].Replace(".", "");
        normalizedEmail = $"{emailParts[0]}@{emailParts[1]}";
    }
    return NormalizeAndHash(normalizedEmail);
}

/// <summary>
/// Normalizes and hashes a string value.
/// </summary>
/// <param name="value">The value to normalize and hash.</param>
/// <returns>The normalized and hashed value.</returns>
private static string NormalizeAndHash(string value)
{
    return ToSha256String(digest, ToNormalizedValue(value));
}

/// <summary>
/// Hash a string value using SHA-256 hashing algorithm.
/// </summary>
/// <param name="digest">Provides the algorithm for SHA-256.</param>
/// <param name="value">The string value (e.g. an email address) to hash.</param>
/// <returns>The hashed value.</returns>
private static string ToSha256String(SHA256 digest, string value)
{
    byte[] digestBytes = digest.ComputeHash(Encoding.UTF8.GetBytes(value));
    // Convert the byte array into an unhyphenated hexadecimal string.
    return BitConverter.ToString(digestBytes).Replace("-", string.Empty);
}

/// <summary>
/// Removes leading and trailing whitespace and converts all characters to
/// lower case.
/// </summary>
/// <param name="value">The value to normalize.</param>
/// <returns>The normalized value.</returns>
private static string ToNormalizedValue(string value)
{
    return value.Trim().ToLower();
}
      

PHP

private static function normalizeAndHash(
    string $hashAlgorithm,
    string $value,
    bool $trimIntermediateSpaces
): string {
    // Normalizes by first converting all characters to lowercase, then trimming spaces.
    $normalized = strtolower($value);
    if ($trimIntermediateSpaces === true) {
        // Removes leading, trailing, and intermediate spaces.
        $normalized = str_replace(' ', '', $normalized);
    } else {
        // Removes only leading and trailing spaces.
        $normalized = trim($normalized);
    }
    return hash($hashAlgorithm, strtolower(trim($normalized)));
}

/**
 * Returns the result of normalizing and hashing an email address. For this use case, Google
 * Ads requires removal of any '.' characters preceding "gmail.com" or "googlemail.com".
 *
 * @param string $hashAlgorithm the hash algorithm to use
 * @param string $emailAddress the email address to normalize and hash
 * @return string the normalized and hashed email address
 */
private static function normalizeAndHashEmailAddress(
    string $hashAlgorithm,
    string $emailAddress
): string {
    $normalizedEmail = strtolower($emailAddress);
    $emailParts = explode("@", $normalizedEmail);
    if (
        count($emailParts) > 1
        && preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1])
    ) {
        // Removes any '.' characters from the portion of the email address before the domain
        // if the domain is gmail.com or googlemail.com.
        $emailParts[0] = str_replace(".", "", $emailParts[0]);
        $normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]);
    }
    return self::normalizeAndHash($hashAlgorithm, $normalizedEmail, true);
}