Prompt
How do I set up custom tracking for email sends?
Latest observation
Custom tracking for email sends usually means you want to measure things like:
- Deliveries: did the email reach the recipient server?
- Opens: did the recipient open the email?
- Clicks: did they click a link?
- Conversions: did they complete an action after clicking?
The exact setup depends on the email platform you’re using, but the common approaches are:
1) Use your ESP’s built-in tracking
Most email service providers (ESP) like SendGrid, Mailchimp, SES + analytics tools, Postmark, etc. support:
- open tracking via a tracking pixel
- click tracking via rewritten links
- webhook events for delivered/opened/clicked/bounced/unsubscribed
You usually enable this in the provider dashboard or API settings.
2) Add your own identifiers to each email
To track individual sends, include a unique ID in every message:
- recipient ID
- campaign ID
- message ID
Example:
campaign_id=summer_sale_2026message_id=abc123
You can store this in:
- headers
- metadata/custom args
- your own database
3) Track clicks with tagged URLs
Append UTM parameters or custom query params to links:
https://example.com/offer?utm_source=email&utm_campaign=summer_sale&message_id=abc123
If you want more control, use your own redirect endpoint:
https://track.yoursite.com/click/abc123?redirect=https://example.com/offer
Then log the click before redirecting.
4) Track opens with a pixel
Embed a 1x1 transparent image:
<img src="https://track.yoursite.com/open/abc123" width="1" height="1" alt="" />
When the email loads images, your server logs the open.
Note: open tracking is imperfect because many clients block images or prefetch them.
5) Listen to webhook events
If your provider offers event webhooks, configure them to send events to your app:
- delivered
- bounced
- opened
- clicked
- spam complaint
- unsubscribed
Then update your database/reporting system from those events.
6) Store/send logs in your app
A solid setup is:
- Generate a unique message ID
- Send email through provider with that ID in metadata
- Log the send in your DB
- Receive provider webhooks for events
- Match events back to the send record
- Update analytics dashboards
Example architecture
- App sends email with
message_id - ESP sends delivery/open/click webhooks
- Tracking service receives webhook and writes to DB
- Dashboard queries DB for stats
Important notes
- Be mindful of privacy laws and consent requirements
- Open tracking may be inaccurate due to Apple Mail Privacy Protection and image blocking
- For clicks, redirects are usually more reliable than open tracking
- Make sure webhook endpoints verify signatures to prevent spoofing
If you tell me which provider or stack you’re using, I can give you exact setup steps and code.