This Google Tag Manager (GTM) Custom Template allows you to normalise and hash email addresses and phone numbers using SHA-256 and push the results into the dataLayer. It supports normalization steps such as trimming, lowercasing, format cleanup, and domain filtering.
Built by Daniel Perry-Reed – marketing analytics specialist at Data to Value.
- Normalise email address (trim, lowercase, remove alias, remove Gmail dots)
- Normalise phone number (optional trimming, strip formatting, enforce E.164 format)
- Blocklist and allowlist domains filtering for email addresses
- SHA-256 hashing for normalised email address and phone number
- All outputs pushed into the
dataLayerwith a configurable event anme - Optional
user_datadataLayer object for ad platform integrations - Configurable debug logging for all steps
- Download the
user_data_hasher_container.jsoncontainer export here - In GTM: go to Admin > Import Container.
- Choose Merge and select the target workspace.
- Click Confirm to import everything.
Included in the container is:
- The tag template
- A tag using the template
- Query string variables for
emailandphone - A trigger using the
data_hasherdataLayer event - A GA4 event (
user_data) including the user_data fields for User Provided Data collection (i.e. Enhanced Conversions)
- Go to Templates > Tag Templates > New
- Paste the full code into the Code tab from
./user_data_hasher_template.jshere
| Field Type | Name | Display Name |
|---|---|---|
| Text Input | emailAddress |
Email Address |
| Checkbox | doDecode |
Decode URL-encoded input |
| Checkbox | doTrimPhone |
Trim phone number |
| Checkbox | doTrim |
Trim email |
| Checkbox | doLowercase |
Lowercase email |
| Checkbox | removePlusAlias |
Remove +alias from email |
| Checkbox | removeDotsInLocalPart |
Remove dots in Gmail local part |
| Text Input | blockedDomains |
Blocked Domains (comma-separated) |
| Text Input | allowedDomains |
Allowed Domains (comma-separated) |
| Text Input | phoneNumber |
Phone Number |
| Checkbox | prefixPlusIfMissing |
Add + if missing |
| Checkbox | stripPhoneFormatting |
Remove formatting (dashes, spaces) |
| Text Input | eventName |
Event Name |
| Checkbox | enableDebug |
Enable Debug Logging |
| Checkbox | includeUserData |
Include user_data object |
| Checkbox | includeUnhashedInUserData |
Include unhashed email/phone |
| Checkbox | includeHashedInUserData |
Include hashed email/phone |
- Logs to Console
- Reads/Writes dataLayer
- Go to Tags > New and select Tag Configuration > Choose tag type > Tag Templates > [Your Template Name]
- Fill in the email and/or phone number fields using GTM Variables or static input
- Enable the normalization and hashing options you need
- Optionally, configure the
eventName,user_datasettings, and debugging preferences
- Click Triggering > Choose a trigger to determine when to fire the tag (e.g., Form Submission, Page View, Custom Event)
- Click Preview in GTM and follow the steps to open your site in debug mode (try a URL like
https://mysite.com/?email=EmAIl.AddRESS+hi@Gmail.com&phone=+44(0)1-2345-67890and use the query string varibales for email address 'email' and phone number 'phone' to test) - Use the browser's Developer Tools to view
dataLayeroutput - Review any logs shown in the console if debug logging is enabled
{
"event": "data_hasher",
"original_email_address": " Examp.le+123@gmAIL.com",
"normalised_email_address": "example@gmail.com",
"hashed_email_address": "abc123...",
"origianl_phone_number": "(1)23-456-78901 "
"normalised_phone_number": "+12345678901",
"hashed_phone_number": "def456...",
"user_data": {
"email_address": "example@gmail.com",
"sha256_email_address": "abc123...",
"phone_number": "+12345678901",
"sha256_phone_number": "def456..."
}
}Built and maintained by myself and the team at Data to Value — your data activation partner helping marketing teams transform data into predictable revenue and growth.
MIT