瞭解如何登錄來源,將點擊和瀏覽歸因於適當事件。
歸因來源是與廣告相關的事件 (點擊或瀏覽),廣告技術可將下列資訊附加至歸因來源:
- 內容比對報表資料,例如廣告素材 ID、廣告活動資訊或地理位置。
- 轉換目的地,也就是您預期使用者完成轉換的所在網站。
按照本文中的步驟操作,即可註冊來源 (廣告曝光或點擊),瀏覽器隨後會將轉換歸因於這些來源。
註冊方式
如要登錄歸因來源,請使用 HTML 元素或 JavaScript 呼叫:
<a>標記<img>標記<script>標記fetch通話XMLHttpRequestwindow.open通話
這會產生網路要求,您隨後會以來源註冊 HTTP 回應標頭回應。
登錄點擊或瀏覽的來源
如要登錄點擊或瀏覽的歸因來源,請按照這裡的步驟操作。完整步驟如下。摘要如下:
- 啟動來源註冊程序。使用 HTML 元素或 JavaScript 呼叫提出要求。點擊和觀看次數的步驟不同,詳情請參閱下節。
完成來源登錄,方法是使用來源登錄標頭回應。收到該要求後,請使用
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 呼叫來註冊來源時,您可能需要使用 attributionsrc 或 attributionReporting。如要瞭解何時需要提供這些資訊,請參閱下表。
如果 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 make sure 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"}
後續步驟
瞭解如何註冊歸因觸發條件。