Exploring the Attribution Reporting API: Privacy-Friendly Conversion Tracking

developer at laptop coding while sitting outside a coffee shop with analytics numbers

What Is the Attribution Reporting API?

Advertisers often want to track how well their ads perform: How many users saw the ad? How many converted into purchases? Traditional tracking methods rely on third-party cookies, which compromise user privacy by sharing data across domains. The Attribution Reporting API solves this by enabling conversion tracking without exposing users’ personal browsing data.

Key Features

How It Works

Components of the API

HTTP Headers

The API uses HTTP headers to register attribution sources and triggers.

HTML Attributes

The `attributionsrc` attribute on elements like `<a>`, `<img>`, and `<script>` specifies attribution data.

JavaScript Methods

You can programmatically register sources and triggers using `fetch()` or `XMLHttpRequest` with the appropriate options.

HTML
				
					<!DOCTYPE html>
<html lang="en">
    
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Attribution Reporting API</title>
    <script src="attribution.js" defer></script>
</head>
<body>
    <!-- Ad link with attribution -->
    <a href="https://shop.example/product" attributionsrc="https://adserver.example/register-source" target="_blank" rel="noopener">
        <img decoding="async" data-src="https://adserver.example/banner.jpg" alt="Product Ad" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==" class="lazyload">
    </a>
</body>
</html>


				
			
JavaScript
				
					// Trigger attribution when a conversion occurs (e.g., "Add to Cart" click)
const registerTrigger = () => {
	fetch('https://shop.example/register-trigger', {
		method: 'POST',
		headers: {
			'Attribution-Reporting-Eligible': 'trigger',
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			event: 'add_to_cart',
			productId: '12345',
			value: 49.99
		})
	}).then((response) => {
		if (response.ok) {
			console.log('Attribution trigger registered successfully');
		} else {
			console.error('Failed to register attribution trigger');
		}
	});
};

// Simulate conversion trigger
document
	.querySelector('#add-to-cart')
	.addEventListener('click', registerTrigger);

// Server-Side: Responding with Attribution Headers

// On the server, include the appropriate headers in the response to mark attribution sources or triggers.
// HTTP/1.1 200 OK
// Attribution-Reporting-Register-Source: source-event-id=1234, destination=https://shop.example

// For triggers:
// HTTP/1.1 200 OK
// Attribution-Reporting-Register-Trigger: trigger-data=conversion-id-5678

				
			
more posts:
Online video streaming platform and digital content management concept with media player interface, cloud library, and multimedia files on laptop, representing content distribution, video marketing
Code

Breaking into the Pipeline: Real-Time Frame Manipulation with the Insertable Streams for MediaStreamTrack API

The experimental Insertable Streams for MediaStreamTrack API closes a long-standing gap in web multimedia by treating live camera feeds as standard Web Streams. By piping individual VideoFrame objects through a TransformStream and recording the transformed output via MediaRecorder, developers can execute frame-by-frame processing—like real-time filtering, watermarking, and computer vision overlays—without relying on hidden canvas hacks.

Discover More »
Apps & Custom Software

What Building Our Own App Taught Us About Building Yours

When Hess WebTech built and launched Tericipe—an Android app that turns printed recipes into a searchable digital collection—in under three months, we had to live with every decision we usually advise clients on. From testing against real-world messy data and handling AI uncertainty to server-side payment security and post-launch maintenance, here are five crucial lessons from our own build that apply to almost any software project.

Discover More »