XMLHttpRequest: phương thức setAttributionReporting()
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Phương thức setAttributionReporting() của giao diện XMLHttpRequest cho biết bạn muốn phản hồi của yêu cầu có thể đăng ký một nguồn phân thuộc tính hoặc trình kích hoạt phân thuộc tính dựa trên JavaScript.
Xem Attribution Reporting API để biết thêm chi tiết.
Cú pháp
setAttributionReporting(options)
Tham số
options-
Một đối tượng cung cấp các tùy chọn báo cáo phân thuộc tính, bao gồm các thuộc tính sau:
eventSourceEligible-
Một boolean. Nếu đặt thành
true, phản hồi của yêu cầu đủ điều kiện đăng ký nguồn phân thuộc tính. Nếu đặt thànhfalse, nó không đủ điều kiện. triggerEligible-
Một boolean. Nếu đặt thành
true, phản hồi của yêu cầu đủ điều kiện đăng ký trình kích hoạt phân thuộc tính. Nếu đặt thànhfalse, nó không đủ điều kiện.
Giá trị trả về
Không có (undefined).
Ngoại lệ
InvalidStateErrorDOMException-
Được ném nếu
XMLHttpRequestliên kết chưa được mở, hoặc đã được gửi. TypeErrorDOMException-
Được ném nếu việc sử dụng Attribution Reporting API bị chặn bởi
Permissions-Policyattribution-reporting.
Ví dụ
const attributionReporting = {
eventSourceEligible: true,
triggerEligible: false,
};
function triggerSourceInteraction() {
const req = new XMLHttpRequest();
req.open("GET", "https://shop.example/endpoint");
// Kiểm tra tính khả dụng của setAttributionReporting() trước khi gọi
if (typeof req.setAttributionReporting === "function") {
req.setAttributionReporting(attributionReporting);
req.send();
} else {
throw new Error("Attribution reporting not available");
// Bao gồm mã khôi phục tại đây nếu phù hợp
}
}
// Liên kết trình kích hoạt tương tác với bất kỳ phần tử và sự kiện nào phù hợp với mã của bạn
elem.addEventListener("click", triggerSourceInteraction);
Các đặc tả kỹ thuật
| Thông số kỹ thuật |
|---|
| Attribution Reporting> # dom-xmlhttprequest-setattributionreporting> |