登錄歸因觸發條件

瞭解如何登錄歸因觸發條件來計算轉換。

歸因觸發條件是指指示瀏覽器擷取轉換的事件。

只要按照本文中的步驟進行,即可登錄觸發條件來登錄轉換,瀏覽器會將轉換歸因至相關來源事件 (也就是廣告曝光或廣告點擊)。

註冊方式

如要登錄觸發條件,請使用 HTML 元素或 JavaScript 呼叫:

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

這項作業會產生網路要求,您會透過觸發事件登錄 HTTP 回應標頭做出回應。

登錄觸發條件以歸因轉換

登錄觸發條件與登錄歸因來源事件類似,本文稍後會說明完整步驟。摘要如下:

  1. 啟動觸發條件登錄。請使用像素或 fetch() 呼叫來提出要求。
  2. 請回應觸發事件登錄標頭,以完成觸發條件登錄

    收到像素要求後,就會傳送至一般 src 屬性中定義的端點;如果您選擇使用 attributionsrc 並指定值,則傳送至 attributionsrc 中定義的端點。請使用標頭 Attribution-Reporting-Register-Trigger 回應。

    在這個標頭中,指定您最終想在報表中顯示的觸發事件資料。任何回應都能設定這個標頭。只要回應能回應來自 destination 的網站發出的要求,系統就會比對來源。瀏覽器收到標頭後,會尋找相符的來源並排定報表時間。

    事件層級報表範例:

    {
      "event_trigger_data": [{
        "trigger_data": "[unsigned 64-bit integer]",
        "priority": "[signed 64-bit integer]",
        "deduplication_key": "[unsigned 64-bit integer]"
      }]
    }
    ```
    
    **Example for summary reports:**
    
    ```json
    {
      ... // existing fields, such as "event_trigger_data"
    
      "aggregatable_trigger_data": [
       {
         "key_piece": "0x400",
         "source_keys": ["campaignCounts"]
       },
       {
         "key_piece": "0xA80",
         "source_keys": ["geoValue", "nonMatchingKeyIdsAreIgnored"]
       }
      ],
      "aggregatable_values": {
        "campaignCounts": 32768,
        "geoValue": 1664
      }
    }
    ```
    

處理子網域

如果 destinationhttps://advertiser.example,則 https://advertiser.example 及其子網域 (例如 https://shop.advertiser.example) 上的轉換都會歸因。

如果 destinationhttps://shop.advertiser.example,就可以歸因 https://advertiser.examplehttps://shop.advertiser.example 上的轉換。

必要和選用屬性

使用 HTML 元素或執行 JavaScript 呼叫來登錄觸發條件時,可能需要使用 attributionsrcattributionReporting。請參閱下表,進一步瞭解何時需要。

如果 attributionsrc 為「選用」,表示該要求符合歸因報表使用資格。如果使用 attributionsrc,瀏覽器會傳送 Attribution-Reporting-Eligible 標頭。此外,應用程式至網頁評估功能也相當實用:如果 attributionsrc 存在,瀏覽器會傳送 Attribution-Reporting-Support 標頭。

註冊方式 觸發條件
<a> 標記 不適用 錨點無法登錄觸發條件。
<img> 標記 attributionsrc選用項目。標頭足以登錄觸發事件。
<script> 標記 attributionsrc選用項目。標頭足以登錄觸發事件。
fetch 項電話素材資源 attributionReporting 選項必要
XMLHttpRequest attributionReporting 選項必要
window.open() 不適用 window.open 無法登錄觸發事件。

步驟 1:啟動觸發條件登錄

您可以使用像素 (<img> 代碼) 或指令碼代碼登錄觸發條件。

使用新的或現有的轉換像素

<img src="https://ad-tech.example/conversionpixel"
     attributionsrc="https://adtech.example/attribution_trigger?purchase=13">

使用指令碼標記

您可以使用指令碼代碼進行觸發條件登錄;運作方式與 <img> 相同。下列程式碼範例說明如何使用 fetch()XMLHttpRequest() (XHR)。

此程式碼有效模擬使用 attributionsrc 的 HTML 要求會執行的動作:

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

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

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

attributionsrc (無論是否含有值)

您可以新增 attributionsrc (無論是否包含值)。

<!-- Without a value -->
<img src="..." width="1" height="1" attributionsrc>

<!--With a value (URL) -->
<img src="..." width="1" height="1" attributionsrc="https://...">

如果你為 attributionsrc 設定了值,這個值必須是單一網址。

使用網址會使瀏覽器發出「個別」保持運作擷取要求 (每個網址各一個要求,其中包含 Attribution-Reporting-Eligible 要求標頭)。

如果您想回應與元素主要要求不同的要求,藉此進行來源登錄,這個方法就非常實用。

舉例來說,如果您需要登錄錨點元素的點擊來源,您實際上可能無法控制目的地。在這種情況下,您會希望設定將來源登錄標頭做為回應,來回應與導覽不同的要求,而且您可以完全控制。指定 attributionsrc 的明確值,就等於指示瀏覽器發出額外的要求,並設定其目的地。

步驟 2:回覆標頭

收到瀏覽器要求後,請回應 Attribution-Reporting-Register-Trigger 標頭,並在回應中加入此標頭:

JSON.stringify({event_trigger_data: [{
      trigger_data: '412444888111012',
      // Optional
      priority: '1000000000000',
      deduplication_key: '2345698765'
    }], debug_key: '1115698977'})

後續步驟

瞭解如何登錄歸因來源