Skip to content

Commit f7ff799

Browse files
authored
Fix examples to also normalize plus character in emails (#1050)
1 parent 1d26beb commit f7ff799

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

examples/remarketing/upload_enhanced_conversions_for_leads.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,12 @@ def normalize_and_hash_email_address(email_address: str) -> str:
254254

255255
# Check that there are at least two segments
256256
if len(email_parts) > 1:
257-
# Checks whether the domain of the email address is either "gmail.com"
258-
# or "googlemail.com". If this regex does not match then this statement
259-
# will evaluate to None.
260-
if re.match(r"^(gmail|googlemail)\.com$", email_parts[1]):
261-
# Removes any '.' characters from the portion of the email address
262-
# before the domain if the domain is gmail.com or googlemail.com.
263-
email_parts[0] = email_parts[0].replace(".", "")
264-
normalized_email = "@".join(email_parts)
257+
# Removes any '.' and '+' characters from the portion of the email address
258+
# before the domain
259+
chars_to_remove = ".+"
260+
translation_table = str.maketrans('', '', chars_to_remove)
261+
email_parts[0] = email_parts[0].translate(translation_table)
262+
normalized_email = "@".join(email_parts)
265263

266264
return normalize_and_hash(normalized_email)
267265

examples/remarketing/upload_enhanced_conversions_for_web.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,12 @@ def normalize_and_hash_email_address(email_address):
233233

234234
# Check that there are at least two segments
235235
if len(email_parts) > 1:
236-
# Checks whether the domain of the email address is either "gmail.com"
237-
# or "googlemail.com". If this regex does not match then this statement
238-
# will evaluate to None.
239-
if re.match(r"^(gmail|googlemail)\.com$", email_parts[1]):
240-
# Removes any '.' characters from the portion of the email address
241-
# before the domain if the domain is gmail.com or googlemail.com.
242-
email_parts[0] = email_parts[0].replace(".", "")
243-
normalized_email = "@".join(email_parts)
236+
# Removes any '.' and '+' characters from the portion of the email address
237+
# before the domain
238+
chars_to_remove = ".+"
239+
translation_table = str.maketrans('', '', chars_to_remove)
240+
email_parts[0] = email_parts[0].translate(translation_table)
241+
normalized_email = "@".join(email_parts)
244242

245243
return normalize_and_hash(normalized_email)
246244

0 commit comments

Comments
 (0)