The ping attribute sends a POST when a link is clicked

Also on X

The ping attribute on <a> makes the browser send an asynchronous POST request to a URL when the link is clicked. You might need this for tracking clicks without redirecting through your own server first. Google uses it in search results, with a workaround for Firefox, which disables ping by default.

<!-- Sends an asynchronous POST request to /track -->
<a href="https://www.reddit.com/" ping="/track">reddit</a>

<!-- Ping several URLs, separated by spaces -->
<a href="https://www.reddit.com/" ping="/track https://tracking.example/">reddit</a>

The request body is just PING with Content-Type: text/ping, and the Ping-From and Ping-To headers tell the server which page the click came from and where it went.

For tracking things other than link clicks, the Beacon API (navigator.sendBeacon()) sends a request that survives the page unloading. It was still experimental when I tweeted this; it now works in every major browser.

More: Spec: hyperlink auditing · Video

← All TILs