This guide explains how to implement
ehash
a hashed version of a user’s email address as a user identifier to enable cross-device tracking and session stitching in GA4.By hashing email addresses collected on-site and sending them as a user property (
ehash
) to GA4, you can help SegmentStream's identity graph more accurately associate sessions and users across devices and channels.To support this:
- All links in marketing emails should include the
ehash
parameter in the URL.
- All email addresses captured onsite (e.g., during checkout or signup) must be hashed client-side and sent to GA4 as user properties.
You don’t need to implement every step at once, each part of the setup provides value on its own. For example, capturing ehash from forms now allows you to start tracking, and adding the parameter to email links can be done later.
This guide outlines all the steps required to fully enable
ehash
based cross-device tracking.Add ehash
to Email Links
When a user submits their email on your site:
- Generate a hash (e.g., using
SHA-256
).
- Store it in your backend.
- Include the hashed email as a query parameter in all email links:
plain texthttps://www.example.com/landing-page?ehash=hashedemail123
This allows you to recognise and associate users on different devices when they click through from an email.
Pass ehash
to GA4 when it’s present in the URL
- Create Variable
- Go to Variables in GTM.
- Click New > Choose Variable Type: URL.
- Set Component Type to
Query
. - In Query Key, enter:
ehash
. - Name it something like
Query - ehash
.
This variable will now dynamically grab
ehash
from the URL if it exists.- Pass it as a User Property to the GA4 Google Tag
- Select your GA4 initialisation Google Tag.
- Open the Shared event settings section and create or edit the Event Settings Variable.
- Inside the variable set the user property name to
ehash
and the value to{{Query - ehash}}
.
This will ensure the ehash parameter is passed to GA4 when there is a ehash parameter in the URL, and SegmentStream will automatically match different devices when they are tracked with the same ehash.
Capture & Hash Emails from On-Site Forms
When a user submits an email (e.g., through a popup or signup form), send an event to GA4 along with the ehash user property by following these steps:
- Add the Hashing Script in GTM (Custom HTML Tag)
- Go to GTM → Tags → New
- Name it:
Custom HTML – Hashed Email Script
- Tag Type: Custom HTML
- Triggering: All Pages
- Paste the following code:
- Your tag should look like this:
- Save
javascript<!-- Load SHA256 library --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/src/sha256.min.js"></script> <script> (function () { // Run after the hashing library loads function onSha256Ready(callback) { if (typeof sha256 === 'function') return callback(); var checkInterval = setInterval(function () { if (typeof sha256 === 'function') { clearInterval(checkInterval); callback(); } }, 50); } onSha256Ready(function () { // 🔧 CHANGE THESE SELECTORS to match your email input and button var input = document.getElementById('email'); // e.g. "#signupEmail" var button = document.querySelector('#form button'); // e.g. "#signupForm button[type='submit']" if (!input || !button) return; button.addEventListener('click', function () { var email = input.value; if (!email) return; var cleanEmail = email.trim().toLowerCase(); var ehash = sha256(cleanEmail); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'hashedEmailCaptured', ehash: ehash }); }); }); })(); </script>
- Create a Data Layer Variable for
ehash
- Go to Variables → New
- Name:
DLV – ehash
- Type: Data Layer Variable
- Data Layer Variable Name:
ehash
- Your variable should look like this:
- Save
- Create a Trigger for
hashedEmailCaptured
- Go to Triggers → New
- Name:
Trigger – Hashed Email Captured
- Trigger Type: Custom Event
- Event name:
hashedEmailCaptured
- Your trigger should look like this:
- Save
- Create a GA4 Tag to Send the Event and User Property
- Go to Tags → New
- Name:
GA4 – Ehash Captured
- Tag Type: Google Analytics: GA4 Event
- Configuration Tag: Select your existing GA4 config tag
- Event Name:
ehash_captured
- User Properties:
- Name:
ehash
- Value:
{{DLV – ehash}}
- Triggering:
Trigger – Hashed Email Captured
- Your tag should look like this:
- Save and publish the container
This ensures the
ehash
parameter is sent to GA4 when a user subscribes to the newsletter. SegmentStream can then automatically match the user if they later click a newsletter link containing the same ehash
, linking it back to the original subscription device.Capture & Hash Email from the Checkout Form
Send an event to GA4 along with the ehash user property before the purchase event by capturing and hashing the email from the checkout form by following these steps:
- Add the Hashing Script in GTM (Custom HTML Tag)
- Go to GTM → Tags → New
- Name it:
Custom HTML – Hashed Checkout Email Script
- Tag Type: Custom HTML
- Triggering: All Pages
- Paste the following code:
- Your tag should look like this:
- Save.
html<!-- Load SHA256 library --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/src/sha256.min.js"></script> <script> (function () { function onSha256Ready(callback) { if (typeof sha256 === 'function') return callback(); var interval = setInterval(function () { if (typeof sha256 === 'function') { clearInterval(interval); callback(); } }, 50); } onSha256Ready(function () { // 🔧 Change selector if your checkout form uses different IDs or structure var input = document.getElementById('email'); var button = document.querySelector('checkout_submit_button'); if (!input || !button) return; button.addEventListener('click', function () { var email = input.value; if (!email) return; var cleanEmail = email.trim().toLowerCase(); var ehash = sha256(cleanEmail); // Push the hashed email to dataLayer before purchase window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'hashedEmailCaptured', ehash: ehash }); }); }); })(); </script>
- Create a Data Layer Variable for
ehash
- Go to Variables → New
- Name:
DLV – ehash
- Type: Data Layer Variable
- Data Layer Variable Name:
ehash
- Your variable should look like this:
- Save.
- Create a Trigger for
hashedEmailCaptured
- Go to Triggers → New
- Name:
Trigger – Hashed Email Captured
- Trigger Type: Custom Event
- Event name:
hashedEmailCaptured
- Your trigger should look like this:
- Save.
- Create a GA4 Tag to Send the Event and User Property
- Go to Tags → New
- Name:
GA4 – Ehash Captured
- Tag Type: Google Analytics: GA4 Event
- Configuration Tag: Select your existing GA4 config tag
- Event Name:
ehash_captured
- User Properties:
- Name:
ehash
- Value:
{{DLV – ehash}}
- Triggering:
Trigger – Hashed Email Captured
- Your tag should look like this:
- Save and publish the container.
This ensures the
ehash
parameter is sent to GA4 right before the moment of purchase. SegmentStream uses this hashed email to match the purchase back to previous touchpoints, such as a newsletter subscription form the user may have filled out earlier, even across different devices.By capturing and hashing the email at both the subscription and checkout stages, SegmentStream can reconstruct the full user journey and attribute value accurately to each marketing interaction the user had before converting.