You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix email/phone normalization and typos in enhanced conversions examples - #1104
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/:
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.
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").
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.
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?
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.
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.
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
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
removed
the
kokoro:run
This label is required to run a kokoro presubmit if an external contributor sends a PR.
label
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes normalization and comment/string issues in
examples/remarketing/upload_enhanced_conversions_for_leads.pyandexamples/remarketing/upload_enhanced_conversions_for_web.py, and adds unit/regression tests undertests/examples/remarketing/:Email normalization (
normalize_and_hash_email_address):gmail.com/googlemail.comdomain check removed in Fix example to also normalize plus character in emails #1050 so periods and+suffixes are only stripped forgmail.comandgooglemail.comaddresses, matching the Google Ads API email normalization guidelines."".join(email_address.split()).lower()) before splitting on@, verifieslen(email_parts) == 2, and uses tuple membership pluslocal_part.partition("+")[0].replace(".", "")to strip.characters and+suffixes without regex overhead.raw_record["email"]to"alex.2+myalias@gmail.com"(matching the Java examples) so both dot and+suffix normalization are exercised.Whitespace normalization (
normalize_and_hash):remove_all_whitespace=Falsetonormalize_and_hashin both examples, using"".join(s.split())whenTrue(for email and phone numbers, e.g."+1 800 5550102"->"+18005550102") ands.strip()whenFalse(preserving internal spaces in multiword names and street addresses such as"Mary Jane"or"De La Cruz").Typos, comments, CLI descriptions, and unit tests:
f"order ID {result,order_id}."->f"order ID {result.order_id}."and missing space inupload_enhanced_conversions_for_web.py.SHA-265->SHA-256docstring typo,ArgumentParserdescriptions, comment inaccuracies, and doubled quote typos ("...""and'{ex.request_id}'') in both files.tests/examples/remarketing/upload_enhanced_conversions_for_web_test.pyandtests/examples/remarketing/upload_enhanced_conversions_for_leads_test.py.