XMLHttpRequest: setAttributionReporting() method

Deprecated
To be removed

This feature is pending removal from browsers. Using it now may lead to broken functionality in future updates. Following the announcement that Chrome will maintain its current approach to third-party cookies, Chrome decided to withdraw certain Privacy Sandbox features including the attribution reporting API.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

The setAttributionReporting() method of the XMLHttpRequest interface indicates that you want the request's response to be able to register a JavaScript-based attribution source or attribution trigger.

See the Attribution Reporting API for more details.

Syntax

js
setAttributionReporting(options)

Parameters

options

An object providing attribution reporting options, which includes the following properties:

eventSourceEligible

A boolean. If set to true, the request's response is eligible to register an attribution source. If set to false, it isn't.

triggerEligible

A boolean. If set to true, the request's response is eligible to register an attribution trigger. If set to false, it isn't.

Return value

None (undefined).

Exceptions

InvalidStateError DOMException

Thrown if the associated XMLHttpRequest has not yet been opened, or has already been sent.

TypeError DOMException

Thrown if use of the Attribution Reporting API is blocked by an attribution-reporting Permissions-Policy.

Examples

js
const attributionReporting = {
  eventSourceEligible: true,
  triggerEligible: false,
};

function triggerSourceInteraction() {
  const req = new XMLHttpRequest();
  req.open("GET", "https://shop.example/endpoint");
  // Check availability of setAttributionReporting() before calling
  if (typeof req.setAttributionReporting === "function") {
    req.setAttributionReporting(attributionReporting);
    req.send();
  } else {
    throw new Error("Attribution reporting not available");
    // Include recovery code here as appropriate
  }
}

// Associate the interaction trigger with whatever
// element and event makes sense for your code
elem.addEventListener("click", triggerSourceInteraction);

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also