Last active
September 6, 2024 09:50
-
-
Save stefanatcroud/d42f9783aca0ec2121a82d64e7e911e4 to your computer and use it in GitHub Desktop.
Demonstrate the email transform required for Enhanced Conversions
This file contains 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 the below as a Custom JavaScript variable in GTM and it will use | |
// the Data Layer Variable "DLV - user_email" as the plaintext email input. | |
// | |
// Output will be a preformatted email address adhering to Google's | |
// requirements for Enhanced Conversions. | |
function() { | |
email = {{DLV - user_email}}.trim().toLowerCase().split('@'); | |
return (email[1] === 'gmail.com' || email[1] === 'googlemail.com') | |
? email[0].replaceAll('.','').split('+')[0] + '@' + email[1] | |
: email[0].split('+')[0] + '@' + email[1] | |
} |
This file contains 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
// Demo of the email transform required for Enhanced Conversions | |
// Copy & paste this into e.g. Chrome dev console | |
const userEmails = [ | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]" | |
] | |
for (email of userEmails) { | |
console.log(email + " -> " + transformEmailForEC(email)); | |
} | |
function transformEmailForEC(email) { | |
email = email.trim().toLowerCase().split('@'); | |
return (email[1] === 'gmail.com' || email[1] === 'googlemail.com') | |
? email[0].replaceAll('.', '').split('+')[0] + '@' + email[1] | |
: email[0].split('+')[0] + '@' + email[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment