google-ads-php icon indicating copy to clipboard operation
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

Open frankii91 opened this issue 1 month ago • 1 comments

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):

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 normalizeAndHashEmailAddress so that:
    • they only remove dots from the local-part if the domain is gmail.com or googlemail.com, and
    • they do not strip the +suffix at all.

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);

frankii91 avatar Dec 06 '25 18:12 frankii91