瞭解如何登錄來源,以將點擊和觀看歸因於適當的事件。
「歸因來源」是指廣告相關事件 (點擊或瀏覽),廣告技術可在當中附加下列資訊: - 內容比對報表資料,例如廣告素材 ID、廣告活動相關資訊或地理位置。 - 轉換目的地,就像您希望使用者在網站上完成轉換一樣。
您可以按照本文件中的步驟,登錄瀏覽器做為轉換歸因的來源 (廣告曝光或點擊)。
註冊方式
如要登錄歸因來源,請使用 HTML 元素或 JavaScript 呼叫:
<a>
標記<img>
標記<script>
標記fetch
項電話素材資源XMLHttpRequest
window.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()
。
使用錨定標記
將 attributionsrc
加到要評估曝光或點擊的現有 <a> 代碼中:
<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">
在 JavaScript 案例中,如果您向 attributionsrc
提供值,請務必對該網址進行編碼,以免網址含有特殊字元 (例如「=」),因為這樣會導致參數剖析不正確。
編碼方式如下:
const encodedUrl = encodeURIComponent(
'https://adtech.example/attribution_source?ad_id=...');
window.open(
"https://shoes.example/landing",
"_blank",
attributionsrc=${encodedUrl});
attributionsrc
也可以採用空格分隔的網址清單,如下所示:
<!-- With an anchor tag -->
<a href=... attributionsrc="https://a.example/register-source
https://b.example/register-source">
或這裡使用 window.open()
。
// With window.open()
window.open('...', '_blank', attributionsrc=${encodedUrl1}
attributionsrc=${encodedUrl2})
在這種情況下,兩個網址都會收到 navigation-source-eligible
attributionsrc
要求 (包含 Attribution-Reporting-Eligible
標頭的要求)。
attributionsrc
(無論是否含有值)
如前文所述,您可以在沒有網址的情況下指定 attributionsrc
。您也可以指定單一網址。此外,如果是來源 (不適用於觸發條件),則可以使用空格分隔網址清單。
使用網址會使瀏覽器發出「個別」保持運作擷取要求 (每個網址各一個要求),其中包含 Attribution-Reporting-Eligible
要求標頭。
如果您想回應與元素主要要求不同的要求,藉此進行來源登錄,這個方法就非常實用。
舉例來說,如果您需要登錄錨點元素的點擊來源,您實際上可能無法控制目的地。在這種情況下,您會希望設定將來源登錄標頭做為回應,來回應與導覽不同的要求,而且您可以完全控制。指定 attributionsrc
的明確值,就等於指示瀏覽器發出額外的要求,並設定其目的地。
如需註冊檢視畫面的步驟 1,請前往「分頁」,然後選取「檢視畫面」步驟 1。
如要登錄資料檢視的歸因來源,您可以使用需要加入 attributionsrc
屬性的圖片或指令碼標記。
或者,您也可以使用 JavaScript fetch()
或 XMLHttpRequest()
。
包含圖片
<img attributionsrc
src="https://adtech.example/attribution_source?ad_id=..."/>
使用指令碼
<script attributionsrc
src="https://adtech.example/attribution_source?ad_id=..."/>
您可以視需要為 attributionsrc
指定網址值,方法與指定點擊相同;也就是說,針對圖片或指令碼,您可以設定 attributionsrc
網址或網址,如下所示:
使用單一網址:
attributionsrc="https://adtech.example/attribution_source?ad_id=123"
使用網址清單:
attributionsrc="https://a.example/register-source
https://b.example/register-source"
使用 fetch()
或 XMLHttpRequest()
此程式碼有效模擬使用 attributionsrc
的 HTML 要求會執行的動作:
// With fetch
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 });
// With XHR
const attributionReporting = {
eventSourceEligible: true,
triggerEligible: false,
};
const req = new XMLHttpRequest();
req.open('GET', url);
req.setAttributionReporting(
attributionReporting);
req.send();
如要在步驟 1 中記錄點擊,請前往「分頁」,然後選取「點擊」步驟 1。
步驟 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"}
後續步驟
瞭解如何登錄歸因觸發條件。