To achieve a holistic view of the user journey, it’s essential to capture engagement signals from Email and SMS campaigns—such as opens, clicks, and conversions. While client-side tracking is often blocked by privacy settings and app environments, server-side tracking ensures reliability, better attribution, and GDPR/CMP compatibility.
✅ Why Server-Side for Email/SMS?
- ✅ Avoids tracking being blocked by email clients or privacy features
- ✅ Captures user actions even in AMP or native mobile environments
- ✅ Maintains tracking across device sessions
- ✅ Complies with consent & privacy regulations
- ✅ Links clicks and conversions to campaign IDs reliably
🔧 Prerequisites
- Server-Side GTM container set up (
https://gtm.yourdomain.com
) - Web GTM container installed on site
- Email & SMS platform that supports:
- Open pixel injection
- Click tracking URLs
- GA4 property + Measurement Protocol API Secret
- Consent Management Platform (CMP), optional but recommended
🚀 Step-by-Step Implementation
🔹 Step 1: Email Open Tracking via Server Pixel
Concept: Inject a 1×1 pixel in the email HTML that points to a Server-Side GTM endpoint.
Pixel URL:
https://gtm.yourdomain.com/collect?event=email_open&email_id=abc123&campaign=summer25
Email HTML Example:
<img src="https://gtm.yourdomain.com/collect?event=email_open&email_id={{user_id}}&campaign={{campaign_name}}" width="1" height="1" style="display:none;">
✅ This request will trigger the GA4 Client in your ssGTM container.
🔹 Step 2: Server-Side GTM: Capture Email Opens
Create a GA4 Client (if not already done)
Create a Custom Trigger in Server-Side GTM:
- Condition:
event_name
equalsemail_open
GA4 Event Tag in ssGTM:
- Event Name:
email_open
- User Properties:
email_id
:{{Query - email_id}}
campaign
:{{Query - campaign}}
🔹 Step 3: SMS Click Tracking via Redirect URL
SMS links should route through your server container:
Shortened Link Format:
https://gtm.yourdomain.com/sms-click?user_id=abc123&campaign=promo01&redirect=https%3A%2F%2Fyourdomain.com%2Foffer
Click Handler Setup in Server GTM:
- Create a Custom Client (type: HTTP)
- Parse URL params:
user_id
campaign
redirect
- Fire a GA4 Event Tag:
- Event Name:
sms_click
- User Properties:
user_id
,campaign
- Event Name:
- Redirect user using a Response Header Variable:
return {
statusCode: 302,
headers: {
'Location': decodeURIComponent(request.query.redirect)
}
}
🔹 Step 4: Correlate Conversions with Email/SMS Campaigns
When the user lands on your site and eventually converts, pass the same user_id
and campaign
stored in cookies or session.
Store data from pixel click:
// On landing page
const urlParams = new URLSearchParams(window.location.search);
const userId = urlParams.get('user_id');
const campaign = urlParams.get('campaign');
if (userId && campaign) {
document.cookie = `email_user=${userId}; path=/; max-age=2592000`;
document.cookie = `email_campaign=${campaign}; path=/; max-age=2592000`;
}
🔹 Step 5: Push Data to dataLayer
for Web GTM
<script>
const getCookie = (name) => {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? decodeURIComponent(match[2]) : null;
};
dataLayer.push({
event: 'email_sms_attribution',
email_user: getCookie('email_user'),
email_campaign: getCookie('email_campaign')
});
</script>
🔹 Step 6: Include Attribution Data in Conversions
Update your GA4 purchase/lead tag in Web GTM:
Parameters:
email_user
:{{DLV - email_user}}
email_campaign
:{{DLV - email_campaign}}
If using Server-Side GTM, ensure you forward these fields as parameters to your server GA4 tag.
✅ Use GA4 Custom Dimensions to persist email_campaign
🔹 Step 7: Reporting in GA4
Create Custom Dimensions for:
email_campaign
sms_campaign
user_id
(hashed or UUID)
Then build Explorations:
- Campaign → Clicks → Purchases
- Users by campaign over time
- Email open vs conversion rate
🔹 Step 8: Consent Mode & Privacy Handling
Ensure no tracking fires until consent is granted.
In GTM:
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied'
});
Use Consent Triggers in both Web and Server containers.
🔹 Step 9: Debugging Tips
- Use GTM Server-Side Preview to see pixel and redirect hits
- Check
/collect?event=email_open
payloads - Log redirected SMS click URL activity
- Validate GA4 Realtime → filter by
email_campaign
- Use Looker Studio for aggregated attribution reports
🔐 Security Notes
- Sanitize incoming query params on ssGTM endpoint
- Avoid exposing raw emails—use hashed
email_id
(e.g., SHA-256) - Ensure redirect URLs are validated to prevent open redirects
🧠 Summary
Step | Action |
---|---|
1 | Use open tracking pixels for email |
2 | Set up GA4 event for email_open |
3 | Redirect and log SMS clicks via ssGTM |
4 | Store user/campaign IDs in cookies |
5 | Push attribution into GA4 conversion events |
6 | Use custom dimensions for campaign attribution |
7 | Implement consent-aware triggers |
8 | QA via GTM debug & GA4 DebugView |