XMLHttpRequest:setAttributionReporting() 方法
XMLHttpRequest 介面的 setAttributionReporting() 方法表示您希望請求的響應能夠註冊一個基於 JavaScript 的歸因源或歸因觸發器。
有關更多詳細資訊,請參閱 歸因報告 API。
語法
js
setAttributionReporting(options)
引數
options-
提供歸因報告選項的物件,包括以下屬性:
eventSourceEligible-
一個布林值。如果設定為
true,則請求的響應有資格註冊歸因源。如果設定為false,則沒有。 triggerEligible-
一個布林值。如果設定為
true,則請求的響應有資格註冊歸因觸發器。如果設定為false,則沒有。
返回值
無 (undefined)。
異常
InvalidStateErrorDOMException-
如果在關聯的
XMLHttpRequest尚未開啟,或者已經傳送,則丟擲。 TypeErrorDOMException-
如果 歸因報告 API 的使用被
attribution-reportingPermissions-Policy阻止,則丟擲。
示例
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);
規範
| 規範 |
|---|
| 歸因報告 # dom-xmlhttprequest-setattributionreporting |
瀏覽器相容性
載入中…