google-ads-php
google-ads-php copied to clipboard
normalizeAndHashEmailAddress - Inconsistent email normalization rules between docs and enhanced conversions samples + PHP `strtolower` vs `mb_strtolower` for UTF-8
Hi,
while implementing Enhanced Conversions for Web with PHP 8.3 I ran into two related inconsistencies:
1. Email normalization: docs vs language samples
On this Google Ads API documentation page:
- “Manage online click conversions” → “Normalize and hash user-provided data”
https://developers.google.com/google-ads/api/docs/conversions/upload-online https://developers.google.com/doubleclick-advertisers/guides/conversions_ec
the “Normalize and hash user-provided data” section says (paraphrased):
- trim leading/trailing whitespace
- convert text to lowercase
- format phone numbers to E.164
-
for email addresses: remove all
.characters in the username (before@) and remove the+symbol together with everything after it in the username, for example[email protected]→[email protected],[email protected]→[email protected].
This reads as a general rule for all email domains.
On the same page (and in the client libraries), the language samples for Enhanced Conversions, e.g. UploadEnhancedConversionsForWeb:
- Java / C# / PHP / Ruby / Perl all implement
normalizeAndHashEmailAddressso that:- they only remove dots from the local-part if the domain is
gmail.comorgooglemail.com, and - they do not strip the
+suffixat all.
- they only remove dots from the local-part if the domain is
For example, the PHP sample here:
- https://github.com/googleads/google-ads-php/blob/main/examples/Remarketing/UploadEnhancedConversionsForWeb.php
contains a helper roughly like:
$normalizedEmail = strtolower($emailAddress);
$emailParts = explode("@", $normalizedEmail);
if (count($emailParts) > 1 && preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1])) {
// remove '.' only for gmail.com / googlemail.com
$emailParts[0] = str_replace(".", "", $emailParts[0]);
$normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]);
}
return self::normalizeAndHash($hashAlgorithm, $normalizedEmail);