Developers
Email Tracking
See who opened your own receipts, newsletters and follow-ups, and what they clicked, on the same path as their visits to your site.
Email tracking comes with any upgraded token plan. See Pricing.
How It Works
For email you send yourself: receipts, newsletters, sales sequences. Add a tiny picture for opens and wrap your links for clicks, and both join the reader’s path, right before the visit the click starts. Sending through Postmark or SendGrid? Their own tracking can come in through Incoming Webhooks instead.
Signing links needs a secret key (stt_sk_) with events:write: see Events From Your Server. The open picture needs no key.
The Open Picture
<img src="https://c.stattery.com/o/example.com/MESSAGE-ID.gif?g=EMAIL-HASH" width="1" height="1" alt="">
MESSAGE-IDis your own id for the email: up to 100 letters, digits, dashes, dots, underscores, colons or @.EMAIL-HASHis the SHA-256 (hex) of the reader’s lowercased email. Leavegout if you don’t know it.- It answers a 1×1 picture that is never cached, and records Email Opened with
message_id.
Signed Click Links
A click link goes through Stattery, is recorded as Email Clicked, and goes on to your page:
https://c.stattery.com/c/example.com/MESSAGE-ID?u=URL-ENCODED-DESTINATION&g=EMAIL-HASH&sig=SIGNATURE
The signature is the hex HMAC-SHA256 of destination + "\n" + message id + "\n" + email hash (an empty hash when there is none). Its key is the hex SHA-256 of your secret key, used as text: Stattery keeps only that hash, so that is what it checks.
// Node.js
import crypto from 'node:crypto';
const sha = s => crypto.createHash('sha256').update(s).digest('hex');
const keyHash = sha(process.env.STATTERY_SECRET_KEY);
export function trackedLink(url, msgId, email) {
const gh = email ? sha(email.trim().toLowerCase()) : '';
const sig = crypto.createHmac('sha256', keyHash).update(`${url}\n${msgId}\n${gh}`).digest('hex');
return `https://c.stattery.com/c/example.com/${msgId}?u=${encodeURIComponent(url)}&g=${gh}&sig=${sig}`;
}
export const openPixel = (msgId, email) =>
`<img src="https://c.stattery.com/o/example.com/${msgId}.gif?g=${email ? sha(email.trim().toLowerCase()) : ''}" width="1" height="1" alt="">`;
<?php
function stattery_link( $url, $msg_id, $email = '' ) {
$key_hash = hash( 'sha256', getenv( 'STATTERY_SECRET_KEY' ) );
$gh = $email ? hash( 'sha256', strtolower( trim( $email ) ) ) : '';
$sig = hash_hmac( 'sha256', "$url\n$msg_id\n$gh", $key_hash );
return "https://c.stattery.com/c/example.com/$msg_id?u=" . rawurlencode( $url ) . "&g=$gh&sig=$sig";
}
Nobody can turn your links into a redirect to somewhere else. A link whose address, message or hash was changed, one with no signature, one signed with an app key or a revoked key, and any address that isn’t http or https gets a “This link isn’t valid” page and goes nowhere.
Machine Opens And Clicks
Many opens and clicks aren’t people: Apple Mail Privacy Protection loads every picture, Gmail and Yahoo fetch them through their own servers, and company mail scanners click links before anyone reads them. Stattery still records these, with machine: true, so you can tell them from a person’s:
- Apple Mail Privacy Protection (Apple’s network).
- Google’s and Yahoo’s image proxies.
- Link scanners such as Barracuda, Proofpoint and Mimecast, and other bot user agents.
A scanner is still sent on to the page, so the real reader’s click later works as usual.
Good To Know
- Opens and clicks count the same as other events.
- A site Stattery doesn’t know still gets the picture, and nothing is recorded.
- A flood of opens from one address is dropped by the flood guard.
- Revoking the key that signed your links stops them working: make a new key and sign new mail with it before you revoke the old one.