HTMLAnchorElement: attributionSrc 屬性
HTMLAnchorElement 介面的 attributionSrc 屬性以程式設計方式獲取和設定 <a> 元素上的 attributionsrc 屬性,反映該屬性的值。attributionsrc 指定您希望瀏覽器傳送 Attribution-Reporting-Eligible 標頭。在伺服器端,這用於觸發在響應中傳送 Attribution-Reporting-Register-Source 標頭,以註冊一個基於導航的歸因來源。
當瀏覽器接收到導航響應時,它會儲存與基於導航的歸因來源相關聯的來源資料(如 Attribution-Reporting-Register-Source 響應標頭中所提供)。
有關更多詳細資訊,請參閱 歸因報告 API。
注意: <a> 元素不能用作歸因觸發器,只能用作來源。
值
一個字串。此屬性有兩個版本可供獲取和設定。
-
空字串,即
aElem.attributionSrc=""。這指定您希望將Attribution-Reporting-Eligible標頭髮送到href屬性指向的同一伺服器。當您在同一伺服器上處理歸因來源註冊時,這是可以的。 -
包含一個或多個 URL 的值,例如
jsaElem.attributionSrc = "https://a.example/register-source https://b.example/register-source";這在所請求的資源不在您控制的伺服器上,或者您只想在不同的伺服器上處理歸因來源註冊的情況下很有用。在這種情況下,您可以將一個或多個 URL 指定為
attributionSrc的值。當發生資源請求時,除了資源來源之外,Attribution-Reporting-Eligible標頭還將傳送到attributionSrc中指定的 URL。這些 URL 然後可以響應Attribution-Reporting-Register-Source來註冊來源。注意:指定多個 URL 意味著可以在同一功能上註冊多個歸因源。例如,您可能正在嘗試衡量不同廣告系列的成功,這涉及生成關於不同資料的不同報告。
示例
設定空的 attributionSrc
<a href="https://shop.example"> Click to visit our shop </a>
const aElem = document.querySelector("a");
aElem.attributionSrc = "";
設定包含 URL 的 attributionSrc
<a href="https://ourshop.example"> Click to visit our shop </a>
// encode the URLs in case they contain special characters
// such as '=' that would be improperly parsed.
const encodedUrlA = encodeURIComponent("https://a.example/register-source");
const encodedUrlB = encodeURIComponent("https://b.example/register-source");
const aElem = document.querySelector("a");
aElem.attributionSrc = `${encodedUrlA} ${encodedUrlB}`;
規範
| 規範 |
|---|
| 歸因報告 # dom-htmlattributionsrcelementutils-attributionsrc |
瀏覽器相容性
載入中…