CM360 线下转化 API 支持使用用户标识符增强基于网站代码的转化。
推荐设置
- 在 CM360 中为您的 Floodlight 配置接受增强型转化服务条款。
- 使用匹配 ID 对您的网站进行插桩处理。
- 记录您的网站上发生的 Floodlight 转化。请务必记录以下所有信息,因为它们是后续 API 调用中的必填字段:
matchId
ordinal
timestampMicros
floodlightActivityId
floodlightConfigurationId
quantity
value
- 在在线代码捕获转化 90 分钟后,调用
conversions.batchupdate
以使用用户标识符增强这些转化。- 用户标识符应设置格式并经过哈希处理,并添加到转化对象的
userIdentifiers
字段中。 - 必须指定数量和值。
您可以选择性地在同一
conversions.batchupdate
调用中调整转化的数量和价值,或提供原始数量和价值。 - 每批插入和更新都可能会同时包含成功和失败。如果转化处理延迟时间比平时长,可重试
NOT_FOUND
失败项(最多 6 小时)。 - 在在线代码捕获转化后的 24 小时内,必须使用用户标识符实现增强型转化。
- 用户标识符应设置格式并经过哈希处理,并添加到转化对象的
归一化和哈希处理
为帮助保护隐私,在上传电子邮件地址、电话号码、名字、姓氏和街道地址之前,必须使用 SHA-256 算法对其进行哈希处理。为了使哈希结果实现标准化,在对其中一个值进行哈希处理之前,您必须:
- 移除开头或结尾处的空格。
- 将文本转换为小写形式。
- 根据 E164 标准设置电话号码的格式。
移除
gmail.com
和googlemail.com
电子邮件地址中域名前面的所有句点 (.)。
C#
/// <summary>
/// Normalizes the email address and hashes it. For this use case, Campaign Manager 360
/// 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();
}
Java
private String normalizeAndHash(MessageDigest digest, String s)
throws UnsupportedEncodingException {
// Normalizes by removing leading and trailing whitespace and converting all characters to
// lower case.
String normalized = s.trim().toLowerCase();
// 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, Campaign Manager 360
* 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);
}
PHP
private static function normalizeAndHash(string $hashAlgorithm, string $value): string
{
return hash($hashAlgorithm, strtolower(trim($value)));
}
/**
* Returns the result of normalizing and hashing an email address. For this use case, Campaign
* Manager 360 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);
}
Python
def normalize_and_hash_email_address(email_address):
"""Returns the result of normalizing and hashing an email address.
For this use case, Campaign Manager 360 requires removal of any '.'
characters preceding "gmail.com" or "googlemail.com"
Args:
email_address: An email address to normalize.
Returns:
A normalized (lowercase, removed whitespace) and SHA-265 hashed string.
"""
normalized_email = email_address.lower()
email_parts = normalized_email.split("@")
# Checks whether the domain of the email address is either "gmail.com"
# or "googlemail.com". If this regex does not match then this statement
# will evaluate to None.
is_gmail = re.match(r"^(gmail|googlemail)\.com$", email_parts[1])
# Check that there are at least two segments and the second segment
# matches the above regex expression validating the email domain name.
if len(email_parts) > 1 and is_gmail:
# Removes any '.' characters from the portion of the email address
# before the domain if the domain is gmail.com or googlemail.com.
email_parts[0] = email_parts[0].replace(".", "")
normalized_email = "@".join(email_parts)
return normalize_and_hash(normalized_email)
def normalize_and_hash(s):
"""Normalizes and hashes a string with SHA-256.
Private customer data must be hashed during upload, as described at:
https://support.google.com/google-ads/answer/7474263
Args:
s: The string to perform this operation on.
Returns:
A normalized (lowercase, removed whitespace) and SHA-256 hashed string.
"""
return hashlib.sha256(s.strip().lower().encode()).hexdigest()
Ruby
# Returns the result of normalizing and then hashing the string using the
# provided digest. Private customer data must be hashed during upload, as
# described at https://support.google.com/google-ads/answer/7474263.
def normalize_and_hash(str)
# Remove leading and trailing whitespace and ensure all letters are lowercase
# before hasing.
Digest::SHA256.hexdigest(str.strip.downcase)
end
# Returns the result of normalizing and hashing an email address. For this use
# case, Campaign Manager 360 requires removal of any '.' characters preceding
# 'gmail.com' or 'googlemail.com'.
def normalize_and_hash_email(email)
email_parts = email.downcase.split("@")
# Removes any '.' characters from the portion of the email address before the
# domain if the domain is gmail.com or googlemail.com.
if email_parts.last =~ /^(gmail|googlemail)\.com\s*/
email_parts[0] = email_parts[0].gsub('.', '')
end
normalize_and_hash(email_parts.join('@'))
end
将用户标识符添加到转化中
首先,照常准备 Conversion
对象以进行上传或修改,然后附加用户标识符,如下所示:
{
"matchId": "my-match-id-846513278",
"ordinal": "my-ordinal-12345678512",
"quantity": 1,
"value": 104.23,
"timestampMicros": 1656950400000000,
"floodlightConfigurationId": 99999,
"floodlightActivityId": 8888,
"userIdentifiers": [
{ "hashedEmail": "0c7e6a405862e402eb76a70f8a26fc732d07c32931e9fae9ab1582911d2e8a3b" },
{ "hashedPhoneNumber": "1fb1f420856780a29719b994c8764b81770d79f97e2e1861ba938a7a5a15dfb9" },
{
"addressInfo": {
"hashedFirstName": "81f8f6dde88365f3928796ec7aa53f72820b06db8664f5fe76a7eb13e24546a2",
"hashedLastName": "799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f",
"hashedStreetAddress": "22b7e2d69b91e0ef4a88e81a73d897b92fd9c93ccfbe0a860f77db16c26f662e",
"city": "seattle",
"state": "washington",
"countryCode": "US",
"postalCode": "98101"
}
}
]
}
成功的响应应如下所示:
{
"hasFailures": false,
"status": [
{
"conversion": {
"floodlightConfigurationId": 99999,
"floodlightActivityId": 8888,
"timestampMicros": 1656950400000000,
"value": 104.23,
"quantity": 1,
"ordinal": "my-ordinal-12345678512",
"matchId": "my-match-id-846513278",
"userIdentifiers": [
{ "hashedEmail": "0c7e6a405862e402eb76a70f8a26fc732d07c32931e9fae9ab1582911d2e8a3b" },
{ "hashedPhoneNumber": "1fb1f420856780a29719b994c8764b81770d79f97e2e1861ba938a7a5a15dfb9" },
{
"addressInfo": {
"hashedFirstName": "81f8f6dde88365f3928796ec7aa53f72820b06db8664f5fe76a7eb13e24546a2",
"hashedLastName": "799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f",
"hashedStreetAddress": "22b7e2d69b91e0ef4a88e81a73d897b92fd9c93ccfbe0a860f77db16c26f662e",
"city": "seattle",
"state": "washington",
"countryCode": "US",
"postalCode": "98101"
}
}
],
"kind": "dfareporting#conversion"
},
"kind": "dfareporting#conversionStatus"
}
]
}
常见错误
在使用用户标识符增强转化时,您可能会遇到以下错误:
- 字段 hashed_X 不是有效的 SHA-256 哈希值
- 所有以“hashed”为前缀的字段仅接受以十六进制形式编码的 SHA-256 哈希值。
- 字段 country_code 的长度错误
country_code
必须正好是 2 个字母。- Floodlight 配置尚未签署增强型转化服务条款
- 对于请求的 Floodlight 配置 ID,尚未接受增强型转化服务条款。
- 指定的 user_identifier 不能超过 5 个
- 一次转化最多只能包含 5 个用户标识符。
常见问题解答
- 为什么建议使用匹配 ID?
- 基于点击 ID 的修改会排除之前未发生点击的转化,并限制增强型转化集成的价值。
- 为什么要记录数量和价值?
- CM360 线下转化 API 要求指定数量和价值。
- 要修改基于代码的线上转化,我需要获取 Google 记录的确切微秒时间戳吗?
- 对于基于匹配 ID 的修改,只要请求中提供的时间戳与 Google 记录的时间戳相差不超过 1 分钟,API 现在就会接受修改。
- 为什么在在线代码捕获到转化后,我需要等待 90 分钟才能进行增强?
- 在线转化最多可能需要 90 分钟才能被 API 编入索引并可供修改。
- 在 API 响应中应注意什么?
- 即使 CM360 Conversion API 返回成功响应,一些单独的转化也可能未能上传或更新。检查各个
ConversionStatus
字段是否失败:NOT_FOUND
失败可以并且应该重试(最长 6 小时),以防转化处理延迟时间比平时长。另请参阅常见问题解答,了解NOT_FOUND
错误为何会持续超过 6 小时。- 不应重试
INVALID_ARGUMENT
和PERMISSION_DENIED
错误。