← 返回目录
来源:Google Ads API 官方文档 · 中文版 · 本地归档

管理在线点击转化

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

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

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

增强型网站转化

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

增强型网站转化需要设置一个代码,该代码会在用户完成转化时自动向 Google Ads 发送点击标识符(例如 GCLID)和订单 ID。您可以通过 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_terms 为 false,请按照 帮助中心

内的说明完成此前提条件。

配置代码植入

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

API 实现

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

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

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

  3. 将 ConversionAdjustment 对象导入 ConversionAdjustmentUploadService。

  4. 查看导入内容。

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

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

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

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

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

为了使哈希结果标准化,请在对以下任一值进行哈希处理之前执行以下操作:

  • 移除开头和结尾处的空格。
  • 将文字转换为小写形式。
  • 根据 E164 标准 设置电话号码的格式。

增强型转化的电子邮件地址格式

为了确保增强型转化的匹配率最高,您必须先正确设置电子邮件地址的格式,然后再进行哈希处理。请按照以下步骤操作:

  1. 应用标准规范化(所有电子邮件地址):

    • 移除任何开头或结尾处的空格。
    • 将整个电子邮件地址转换为小写形式。
  2. 如果适用,请应用 Gmail/Googlemail 特定规范化:

    • 此步骤仅适用于网域为 gmail.com 和 googlemail.com 的电子邮件地址。
    • 移除句点 (.):从用户名部分(“@”之前)移除 所有句点字符。
    • 移除加号后缀 (+):从用户名部分移除加号 (+) 及其后面的所有字符。

      • 示例:Jane.Doe+Shopping@googlemail.com 首先变为 jane.doe+shopping@googlemail.com(小写),然后变为 janedoe@googlemail.com(Gmail/Googlemail 特定规则)。
    • 其他网域:对于网域不是 gmail.com 或 googlemail.com 的电子邮件地址,请勿从用户名中移除句点或加号后缀。 仅对这些地址应用标准规范化(小写、移除空格)。

      • 示例:user.name+NYC@Example.com 将规范化为 user.name+nyc@example.com。
  3. 对规范化的电子邮件地址进行哈希处理:

    • 应用相应的规范化步骤后,使用 SHA-256 算法对生成的电子邮件地址进行哈希处理。

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);
}
在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →