If you ever need help, please email us at support@mixpanel.com
Back to topics

Pixel based event tracking

Updated Nov. 12, 2014

Often it is useful to track an event when a document is rendered, such as an email or newsletter. This can be done by adding a URL directed to a mixpanel API endpoint into the src attribute of an html image tag within the document that will send the event. The URL of the embedded image is the same as the URL for a regular mixpanel request, the only difference is that you add "&img=1" to the end of the URL. The "&img=1" causes Mixpanel to return a 1x1 transparent gif that the program rendering the message will load. When the image renders, the event is logged by mixpanel. Doing this type of pixel tracking is very similar to crafting an HTTP request , and in fact you use the same API endpoint:


Here is an example JSON array that we might generate for an "e-mail opened"" event:

	{"event": "e-mail opened", 
    		"properties": {
        	"distinct_id": "user@mixpanel.com", 
        	"token": "e3bc4100330c35722740fb8c6f5XXXXX", 
        	"time": 1245613885, 
        	"campaign": "employee wellness"

This array must be converted into base 64 before being sent to the API. Once that's done, it can be placed into a URL which will be sent to the API endpoint. The URL is structured like this: [ENDPOINT]/?data=[BASE_64_JSON_EVENT]&ip=1&img=1 .

An example of a correctly formatted URL is:


Be sure that the JSON event array you generate contains a value for distinct_id. If you would like these events to fall under the same unique user as other event in your mixpanel implementation, you must use that user's distinct_id in your event array. There is currently no way to pull the distinct_id of a user; so you must register it at the beginning of your funnel, and re-register it for any events that take place outside of a single user's session.