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を参照してください。
構文
js
setAttributionReporting(options)
引数
options-
帰属レポートのオプションを提示するオブジェクトで、次のプロパティが含まれます。
eventSourceEligible-
論理値。
trueに設定すると、このリクエストのレスポンスは、帰属ソースを登録する対象となります。falseに設定すると、対象外となります。 triggerEligible-
論理値。
trueに設定すると、このリクエストのレスポンスは、帰属トリガーを登録する対象となります。falseに設定すると、対象外となります。
返値
なし (undefined)。
例外
InvalidStateErrorDOMException-
関連付けられた
XMLHttpRequestが開かれるための処理がまだ行われていない場合、またはすでに送信済みである場合に発生します。 TypeErrorDOMException-
帰属レポート API の使用が、
attribution-reportingのPermissions-Policyによってブロックされている場合に発生します。
例
js
const attributionReporting = {
eventSourceEligible: true,
triggerEligible: false,
};
function triggerSourceInteraction() {
const req = new XMLHttpRequest();
req.open("GET", "https://shop.example/endpoint");
// 呼び出す前に setAttributionReporting() が使用できることを確認する
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> |
ブラウザーの互換性
Loading…