登錄歸因來源

瞭解如何登錄來源,將點擊和觀看歸給相應事件。

歸因來源是廣告相關事件 (點擊或瀏覽),廣告技術可附加以下類型的資訊:

  • 內容比對報表資料,例如廣告素材 ID、廣告活動相關資訊或地理位置。
  • 轉換目的地,就像您預期使用者會在哪些網站上完成轉換。

請按照本文件中的步驟登錄來源 (廣告曝光或點擊),讓瀏覽器據此進行轉換歸因。

註冊方式

如要登錄歸因來源,請使用 HTML 元素或 JavaScript 呼叫:

  • <a> 標記
  • <img> 標記
  • <script> 標記
  • fetch 項電話素材資源
  • XMLHttpRequest
  • window.open 項電話素材資源

這會產生網路要求,您接著使用來源登錄的 HTTP 回應標頭回應。

登錄點擊或觀看來源

如要登錄點擊或觀看的歸因來源,請按照本文所述的步驟操作。請完成完整步驟。摘要如下:

  1. 啟動來源登錄。使用 HTML 元素或 JavaScript 呼叫提出要求。這個步驟對於點擊和觀看來說不同,您將在以下各節中說明。
  2. 回應來源登錄標頭,完成來源登錄。收到要求後,請回應 Attribution-Reporting-Register-Source 標頭。並在該標頭中指定所需的 Attribution Reporting 設定。點擊和觀看也是一樣。

    摘要報表範例:

    {
      "aggregation_keys": {
        "campaignCounts": "0x159",
        "geoValue": "0x5"
      },
      "aggregatable_report_window": "86400",
      "destination": "https://example.com"
    }
    

    事件層級報表範例:

    {
      "source_event_id": "12340873456",
      "destination": "[eTLD+1]",
      "expiry": "[64-bit signed integer]",
      "priority": "[64-bit signed integer]",
      "event_report_window": "[64-bit signed integer]"
    }
    

必要和選用屬性

當您使用 HTML 元素或發出 JavaScript 呼叫來登錄來源時,可能需要使用 attributionsrcattributionReporting。請參閱下表,進一步瞭解在哪些情況下需要這些權限。

如果 attributionsrc 為「選用」,使用時表示這項要求符合歸因報表的資格。如果您使用 attributionsrc,瀏覽器會傳送 Attribution-Reporting-Eligible 標頭。此外,這也適合用來評估應用程式至網頁:如有 attributionsrc,瀏覽器會傳送 Attribution-Reporting-Support 標頭。

註冊方式 來源
<a> 標記 (導覽來源)
必要attributionsrc
<img> 標記 (事件來源)
attributionsrc必要項目
<script> 標記 (事件來源)
attributionsrc必要項目
fetch 項電話素材資源 attributionReporting必要選項。
XMLHttpRequest attributionReporting必要選項。
window.open 項電話素材資源 (導覽來源)
必要attributionsrc

步驟 1:開始登錄來源

步驟 1 對點擊和觀看的影響有所不同。

如要登錄點擊的歸因來源,您可以使用 <a> 標記或 JavaScript window.open()

使用錨點

在您要評估曝光或點擊次數的現有 <a> 代碼中加入 attributionsrc

<a href="https://shoes.example/..." attributionsrc>Click me</a>

詳情請參閱範例程式碼

使用指令碼

attributionsrc 呼叫 window.open()

window.open(
  "https://shoes.example/...",
  "_blank",
  "attributionsrc");

此方法必須在使用者互動後的 5 秒內呼叫。

您不必單獨新增 attributionsrc,能為圖片或指令碼指定單一網址值:

<a href=... attributionsrc="https://a.example/register-source">Click me</a>

如果是 JavaScript 的情況,如果您提供 attributionsrc 值,請務必對該網址進行編碼,以免網址包含可能會正確剖析參數的特殊字元 (例如 =)。

編碼方式如下:

const encodedUrl = encodeURIComponent(
  "https://adtech.example/attribution_source?ad_id=...");
window.open(
  "https://shoes.example/landing",
   "_blank",
   `attributionsrc=${encodedUrl}`);

attributionsrc 也可以採用 <a> 標記,並以空格分隔的網址清單:

<a href=... attributionsrc="https://a.example/register-source
  https://b.example/register-source">Click me</a>

或是在這裡使用 window.open()

window.open("...", "_blank", `attributionsrc=${encodedUrl1}
  attributionsrc=${encodedUrl2}`)

在這種情況下,這兩個網址都會收到符合導覽來源的 attributionsrc 要求 (包含 Attribution-Reporting-Eligible 標頭的要求)。

attributionsrc (無論是否包含值)

如先前所述,您可以在不指定網址的情況下指定 attributionsrc。您也可以指定單一網址。此外,您也可以使用空格分隔的網址清單。

使用網址會導致瀏覽器啟動獨立的保持運作擷取要求 (每個網址一個,包含 Attribution-Reporting-Eligible 要求標頭)。

如果您想透過回應與元素主要要求不同的要求來註冊來源,這個方法就很實用。

舉例來說,如果您需要登錄錨定元素點擊來源,您實際上可能無法控管目的地。在這種情況下,建議您透過設定傳送來源登錄標頭做為回應,做為回應與導覽之外的要求,而您可以完全掌控。只要指定 attributionsrc 的明確值,就能指示瀏覽器發出額外要求,並設定其目的地。

如要登錄資料檢視的歸因來源,可以使用需要加入 attributionsrc 屬性的圖片或指令碼標記。

您也可以使用 JavaScript fetch()XMLHttpRequest()

含有圖片

<img attributionsrc
src="https://adtech.example/attribution_source?ad_id=...">

使用指令碼

<script attributionsrc
  src="https://adtech.example/attribution_source?ad_id=..."></script>

您也可以選擇指定 attributionsrc 的網址值,方法與指定點擊相同;也就是說,針對圖片或指令碼,您可以按照以下方式設定 attributionsrc 網址或網址:

使用單一網址:

<img attributionsrc="https://adtech.example/attribution_source?ad_id=123">

其中包含網址清單:

<img attributionsrc="https://a.example/register-source
  https://b.example/register-source">

正在使用 fetch()XMLHttpRequest()

以下程式碼可有效利用 attributionsrc 模擬 HTML 要求的行為:

const attributionReporting = {
  eventSourceEligible: true,
  triggerEligible: false,
};

// Optionally set keepalive to ensure the request outlives the page.
window.fetch("https://adtech.example/attribution_source?my_ad_id=123",
  { keepalive: true, attributionReporting });
const attributionReporting = {
  eventSourceEligible: true,
  triggerEligible: false,
};

const req = new XMLHttpRequest();
req.open("GET", url);
req.setAttributionReporting(attributionReporting);
req.send();

步驟 2:回應標題 (點擊次數和觀看次數)

點擊和觀看的下一個步驟都是使用 Attribution-Reporting-Register-Source 標頭回應。

詳情請參閱範例程式碼

在伺服器上收到瀏覽器要求後,請在回應中加入 Attribution-Reporting-Register-Source 標頭。

res.set(
  "Attribution-Reporting-Register-Source",
  JSON.stringify({
    // Use source_event_id to map it to any granular information
    // you need at ad-serving time
    source_event_id: "412444888111012",
    destination: "https://advertiser.example",
    // Optional fields
    expiry: "604800",
    priority: "100",
    debug_key: "122939999"
  })
);

字串化後,您的標頭會如下所示:

{"source_event_id":"412444888111012","destination":"https://advertiser.example","expiry":"604800","priority":"100","debug_key":"122939999"}

後續步驟

瞭解如何登錄歸因觸發條件