Skip to contentSkip to navigationSkip to topbar
On this page
Looking for more inspiration?Visit the
(information)
You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.

Tracking Pixel API


Tracking pixels (aka beacon, 1×1 gif, or clear gif) allow for tracking email opens, advertising impressions and checkout pages where JavaScript and POST requests are disallowed, but where you can embed an image.

Follow Segment's HTTP Tracking API to use the /pixel API endpoint, which accepts base64 encoded url ?data and returns an 1x1 transparent gif.


Pixel API endpoint signature:

pixel-api-endpoint-signature page anchor
https://api.segment.io/v1/pixel/<METHOD ENDPOINT>?data=<base64-ENCODED-JSON>
(information)

base64 encoding optional

The base64 encoding is optional, however it prevents special character interpretation or muxing by browsers, or other tools that might interpret URLs. For example, the URL https://www.example.com/ might be altered to http%3A%2F%2Fwww.example.com when appended to another URL, but the base64 version, aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20, remains unchanged.

Pixel Routes

pixel-routes page anchor
1
/v1/pixel/identify
2
/v1/pixel/group
3
/v1/pixel/alias
4
/v1/pixel/page
5
/v1/pixel/screen
6
/v1/pixel/track

Each endpoint always responds with a 200 <empty-gif>, even if an error occurs.

Example Email Opened event:

example-email-opened-event page anchor

Create the payload:

create-the-payload page anchor
1
{
2
"writeKey": "YOUR_WRITE_KEY",
3
"userId": "user_123",
4
"event": "Email Opened",
5
"properties": {
6
"subject": "The Electric Daily",
7
"email": "jane.kim@example.com"
8
}
9
}

Note: you must include either a userId or anonymousId with every API call.

Encode it using base64 and make sure it's URL safe:

encode-it-using-base64-and-make-sure-its-url-safe page anchor

Protip: You can accomplish this with WindowBase64 methods(link takes you to an external page):

eyJ3cml0ZUtleSI6ICJZT1VSX1dSSVRFX0tFWSIsICJ1c2VySWQiOiAiMDI1cGlrYWNodTAyNSIsICJldmVudCI6ICJFbWFpbCBPcGVuZWQiLCAicHJvcGVydGllcyI6IHsgICAic3ViamVjdCI6ICJUaGUgRWxlY3RyaWMgRGFpbHkiLCAgICJlbWFpbCI6ICJwZWVrQXRNZUBlbWFpbC5wb2tlIiB9fQ

If you choose not to encode your payload, send it like this instead:

if-you-choose-not-to-encode-your-payload-send-it-like-this-instead page anchor
https://api.segment.io/v1/pixel/track?userId=user_123&event=Email Opened&properties.subject=The Electric Daily&properties.email=jane.kim@example.com&writeKey=<YOUR_WRITE_KEY>

Add an image tag to your email newsletter with src pointing to a Pixel API route:

add-an-image-tag-to-your-email-newsletter-with-src-pointing-to-a-pixel-api-route page anchor
<img src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6ICJZT1VSX1dSSVRFX0tFWSIsICJ1c2VySWQiOiAiMDI1cGlrYWNodTAyNSIsICJldmVudCI6ICJFbWFpbCBPcGVuZWQiLCAicHJvcGVydGllcyI6IHsgICAic3ViamVjdCI6ICJUaGUgRWxlY3RyaWMgRGFpbHkiLCAgICJlbWFpbCI6ICJwZWVrQXRNZUBlbWFpbC5wb2tlIiB9fQ">