logo

Cross-Device Tracking via Email Hash (Segment)

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 an event parameter (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 event parameters.
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 text
https://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

Implementation Options

You can implement this either:

Option A — Client-side (recommended)

Using analytics.js:
javascript
// Parse ehash from the URL const urlParams =newURLSearchParams(window.location.search); const ehash = urlParams.get("ehash"); if (ehash) { // Attach ehash to all subsequent Segment events as a context field analytics.ready(() => { analytics.addSourceMiddleware(({ payload, next }) => { payload.obj.context = payload.obj.context || {}; payload.obj.context.ehash = ehash; next(payload); }); }); }
This ensures all Segment events automatically include:
json
"context":{ "ehash":"abc123" }
Segment will forward this to GA4.

Option B — Using Segment Functions (Cloud or Source Functions)

If the website is already instrumented and you cannot modify code:
  1. Create a Source Function.
  1. Inspect incoming payloads.
  1. If the URL includes ehash, inject it into context.ehash.
Example:
javascript
async function onTrack(event, settings) { if (event.context?.page?.url) { const url =newURL(event.context.page.url); const ehash = url.searchParams.get("ehash"); if (ehash) { event.context.ehash = ehash; } } return event; }
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 event parameter by following these steps:
  1. Hash the email when a user submits a form.
  1. Send a Segment track() call including the ehash.
Example:
javascript
analytics.track("Email Form Submitted", { ehash:"<sha256 hashed email>", form_id:"newsletter_popup" });

Forwarding ehash to GA4 (Segment Destination settings)

The GA4 Destination in Segment forwards all event properties by default.
So as long as your track() call includes the property below, GA4 will receive this as an event parameter:
json
{ "ehash":"123hashed" }
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 on Checkout

When the purchase is completed and the customer email is available:
  1. Hash the email.
  1. Include it in the Segment Purchase event (or whatever your ecommerce library sends).

Example using Segment's ecommerce spec:

javascript
analytics.track("Order Completed", { order_id:"T12345", total:59.99, currency:"USD", products: [ { product_id:"SKU_123", name:"Wireless Mouse", price:29.99, quantity:2 } ], ehash:"<sha256 hashed email>" });
Segment → GA4 destination will forward ehash automatically.
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.