XMLHttpRequest: setAttributionReporting() メソッド
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
setAttributionReporting()
は XMLHttpRequest
インターフェイスのメソッドで、このリクエストのレスポンスに対して、 JavaScript ベースの帰属ソースまたは帰属トリガーを登録できるようにしたいことを示します。
詳しくは帰属レポート APIを参照してください。
構文
setAttributionReporting(options)
引数
options
-
帰属レポートのオプションを提示するオブジェクトで、次のプロパティが含まれます。
eventSourceEligible
-
論理値。
true
に設定すると、このリクエストのレスポンスは、帰属ソースを登録する対象となります。false
に設定すると、対象外となります。 triggerEligible
-
論理値。
true
に設定すると、このリクエストのレスポンスは、帰属トリガーを登録する対象となります。false
に設定すると、対象外となります。
返値
なし (undefined
)。
例外
InvalidStateError
DOMException
-
関連付けられた
XMLHttpRequest
が開かれるための処理がまだ行われていない場合、またはすでに送信済みである場合に発生します。 TypeError
DOMException
-
帰属レポート API の使用が、
attribution-reporting
のPermissions-Policy
によってブロックされている場合に発生します。
例
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");
// 適切なリカバリーコードをここに入れる
}
}
// 操作トリガーを、コードに意味のある要素やイベントと関連付ける
elem.addEventListener("click", triggerSourceInteraction);
仕様書
Specification |
---|
Attribution Reporting # dom-xmlhttprequest-setattributionreporting |
ブラウザーの互換性
BCD tables only load in the browser