Skip to content

Fix email/phone normalization and typos in enhanced conversions examples - #1104

Open
pattersonlois wants to merge 4 commits into
googleads:mainfrom
pattersonlois:fix-enhanced-conversions-normalization
Open

pattersonlois wants to merge 4 commits into
googleads:mainfrom
pattersonlois:fix-enhanced-conversions-normalization

Conversation

@pattersonlois

@pattersonlois pattersonlois commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes normalization and comment/string issues in examples/remarketing/upload_enhanced_conversions_for_leads.py and examples/remarketing/upload_enhanced_conversions_for_web.py, and adds unit/regression tests under tests/examples/remarketing/:

  1. Email normalization (normalize_and_hash_email_address):

    • Restores the gmail.com / googlemail.com domain check removed in Fix example to also normalize plus character in emails #1050 so periods and + suffixes are only stripped for gmail.com and googlemail.com addresses, matching the Google Ads API email normalization guidelines.
    • Strips leading, trailing, and intermediate whitespace ("".join(email_address.split()).lower()) before splitting on @, verifies len(email_parts) == 2, and uses tuple membership plus local_part.partition("+")[0].replace(".", "") to strip . characters and + suffixes without regex overhead.
    • Updates the sample raw_record["email"] to "alex.2+myalias@gmail.com" (matching the Java examples) so both dot and + suffix normalization are exercised.
  2. Whitespace normalization (normalize_and_hash):

    • Adds remove_all_whitespace=False to normalize_and_hash in both examples, using "".join(s.split()) when True (for email and phone numbers, e.g. "+1 800 5550102" -> "+18005550102") and s.strip() when False (preserving internal spaces in multiword names and street addresses such as "Mary Jane" or "De La Cruz").
  3. Typos, comments, CLI descriptions, and unit tests:

    • Fixes f"order ID {result,order_id}." -> f"order ID {result.order_id}." and missing space in upload_enhanced_conversions_for_web.py.
    • Fixes SHA-265 -> SHA-256 docstring typo, ArgumentParser descriptions, comment inaccuracies, and doubled quote typos ("..."" and '{ex.request_id}'') in both files.
    • Adds unit and regression tests in tests/examples/remarketing/upload_enhanced_conversions_for_web_test.py and tests/examples/remarketing/upload_enhanced_conversions_for_leads_test.py.

@aleksUIX

Copy link
Copy Markdown

normalize_and_hash() also builds hashed_first_name and hashed_last_name in the web example, so this change hashes Mary Jane as maryjane. The enhanced-conversions guide and its Java/PHP address examples preserve internal spaces. These are different identifiers for matching. Can we keep trim-and-lowercase for names, remove internal whitespace only for phone numbers, and add a regression test with a multiword first or last name?

@pattersonlois

Copy link
Copy Markdown
Contributor Author

Thanks @aleksUIX and @bobhancockg for catching these issues! Addressed all feedback in 2b2daf9:

  • normalize_and_hash(): Added remove_all_whitespace=False in both examples ("".join(s.split()) when True for email and phone numbers; s.strip() when False to preserve inner spaces in multiword names and street addresses), passing remove_all_whitespace=True at the phone call sites and keeping first_name and last_name at the default False.
  • normalize_and_hash_email_address(): Stripped whitespace via "".join(email_address.split()).lower() before .split("@"), required len(email_parts) == 2, replaced the regexes with domain in ("gmail.com", "googlemail.com") and local_part.partition("+")[0].replace(".", ""), and removed the unused import re from both files.
  • Sample raw_record["email"]: Updated both examples to "alex.2+myalias@gmail.com" (matching the Java examples) so both dot and + suffix removal are exercised when running main().
  • Unit and regression tests: Added tests/examples/remarketing/upload_enhanced_conversions_for_web_test.py and tests/examples/remarketing/upload_enhanced_conversions_for_leads_test.py covering multiword names ("Mary Jane", "De La Cruz"), phone whitespace removal, Gmail/Googlemail/non-Gmail/spaces-around-@/multi-@ email normalization, and main() call-site wiring.

@pattersonlois

Copy link
Copy Markdown
Contributor Author

Thanks @bobhancockg! Addressed both comments in 192005a:

  • GoogleAdsClient initialization: Simplified _create_client_with_mock_services in both upload_enhanced_conversions_for_leads_test.py and upload_enhanced_conversions_for_web_test.py to pass only credentials and use_proto_plus=True so the tests use the library's default API version.

@aleksUIX

Copy link
Copy Markdown

Checked 192005a9 after your update. The exact helpers preserve the spaces in Mary Jane and De La Cruz and strip phone whitespace in both examples. All six isolated checks pass; the old helper fails the multiword-name check. The call sites keep names on the default path. This addresses my finding. I did not run the full client suite.

@Raibaz Raibaz added the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Nov 20, 2026
@kokoro-team kokoro-team removed the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants