Skip to content

normalizeAndHashEmailAddress - Inconsistent email normalization rules between docs and enhanced conversions samples + PHP strtolower vs mb_strtolower for UTF-8 #1119

@frankii91

Description

@frankii91

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:

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 jane.doe@example.comjanedoe@example.com, janedoe+newsletter@example.comjanedoe@example.com.

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNeed triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions