Table of Contents

Web Analytics - Pixel (1×1 gif, Clear Gif)

About

Tracking pixels (aka beacon, 1×1 gif, or clear gif) is a tracker that allow for tracking where a POST requests are disallowed (mostly to track Open Email), but where you can embed an image that will perform a get with data passed in query string

Pro/Cons

Usage

Syntax

Raw data

https://trackingapi.example.com/endpoint?att1=value1&att2=value2...

Example:

Json Encoded

https://trackingapi.example.com/endpoint?data=<base64-ENCODED-JSON>

where:

Example

The IMG tag

<img id="pixel" src="https://api.example.com/pixel/track?data=xxxxthedataxxx" style="display:none">

Json Payload Encoding

let payload = {
  "userId": "025pikachu025",
  "event": "Email Opened",
  "properties": {
    "subject": "The Electric Daily",
    "email": "[email protected]"
  }
}
let encodedData = window.btoa(JSON.stringify(payload));
console.log("The payload encoded is: "+encodedData);

Return a 1×1 image in Php

How to send a 1×1 image as response in php. Source

$img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
header('Content-Type: image/gif');
header('Content-Length: '.strlen($img));
header('Connection: Close');
print $img;
tpl_flush();

Documentation / Reference