trackablemail
v1.0.2
Published
A lightweight Node.js utility to track whether your sent emails have been opened by embedding a tracking pixel.
Readme
📦 TrackableMail
A lightweight Node.js utility to track whether your sent emails have been opened by embedding a tracking pixel.
🚀 Installation
Install the package via NPM:
npm install trackablemail
Step 1: Generate a Tracking URL
Use the provided function to generate a unique tracking URL for each email recipient.
const { createTrackingPixel } = require('trackablemail');
const trackingUrl = createTrackingPixel({
recipient: '[email protected]',
subject: 'Welcome Email',
baseUrl: 'https://yourdomain.com/track'
});
console.log(trackingUrl);
// Output: https://yourdomain.com/track?uid=xyz123&cid=abc456Step 2: Embed the Tracking Pixel in Your Email
Insert the generated URL in your email HTML:
<img
src="https://yourdomain.com/track?uid=xyz123&cid=abc456"
width="1"
height="1"
alt="."
/>🛠️ Example: Express Backend Route
Set up a tracking endpoint on your server to handle requests:
const express = require('express');
const app = express();
app.get('/track', (req, res) => {
const { uid, cid } = req.query;
// Log or store tracking data here
console.log(`Email opened by UID: ${uid}, Campaign: ${cid}`);
// Return a transparent 1x1 GIF pixel
const pixel = Buffer.from(
'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
'base64'
);
res.set('Content-Type', 'image/gif');
res.send(pixel);
});
app.listen(3000, () => {
console.log('Tracking server running on http://localhost:3000');
});
