在 Protected Audience 中搭配程式輔助出價使用 Topics

瞭解如何使用 Topics 的興趣,做為 Protected Audience 出價和競價程序的輸入內容。Protected Audience 有數個面向,買方和賣方可以將第一方信號傳遞至出價和競價程序。Topics 提供的信號可運用在出價和廣告選擇過程中,補充目前使用者興趣的相關資訊,藉此提高廣告空間的潛在價值。

閱讀本指南前,請務必熟悉 TopicsProtected Audience 這兩個概念。

取得主題

呼叫 Topics API 時,呼叫端會看到之前針對該瀏覽器觀察到的一組主題。

const currentTopics = await document.browsingTopics();
// Example result
[
 
{
   
"configVersion": "chrome.2",
   
"modelVersion": "4",
   
"taxonomyVersion": "2",
   
"topic": 310,
   
"version": "chrome.2:2:4"
 
}
]

在這個案例中,主題:310 對應至「運動/自行車」

下列範例顯示直接使用的主題值,但對於完整實作項目,可以選擇處理或與其他資料合併。

使用主題,根據條件定義興趣群組

產生的主題可直接用來選擇將使用者加入興趣群組。

if (currentTopics[0].topic === 310) { // Interest in "Sports/Cycling"
 
const interestGroup = {
  owner
: 'https://dsp.example',
  name
: 'custom-bikes',
 
}
}

為興趣群組提供買方主題

建立興趣群組時,您可以將目前的主題 (或已經處理的資料) 加入 userBiddingSignals。如此一來,買方就能在出價時使用主題

const interestGroup = {
  owner
: 'https://dsp.example',
  name
: 'custom-bikes',
  userBiddingSignals
: {
    topics
: currentTopics,
   
....
 
},
 
...
};

navigator
.joinAdInterestGroup(interestGroup, 7 * kSecsPerDay);

為競價提供賣方主題

設定競價時,賣方可以看到 (或從這些主題處理的資料) 會納入 auctionSignalssellerSignalsperBuyerSignals 的組合。如此一來,買方就能在出價時使用主題,賣方可以使用主題為出價評分

const myAuctionConfig = {
  seller
: 'https://ssp.example',
  auctionSignals
: {
    topics
: currentTopics,
 
},
  sellerSignals
: {
    topics
: currentTopics,
 
},
  perBuyerSignals
: {
   
'https://dsp.example': {
      topics
: currentTopics,
     
// ...
   
},
   
// ...
 
},
 
// ...
};
const result = await navigator.runAdAuction(myAuctionConfig);

根據主題設定出價

這樣一來,呼叫買方的 generateBid() 函式時,傳入的記錄主題即可用於出價,就像信號中提供的任何其他資料一樣。舉例來說,出價工具可能會使用「運動/自行車」用這個 custom-bikes 個興趣群組提高出價。

generateBid(interestGroup, auctionSignals, perBuyerSignals,
    trustedBiddingSignals
, browserSignals) {
 
const topics = interestGroup.userBiddingSignals.topics;
 
// Use the topic values in the bidding logic.
}

根據主題為出價評分

呼叫賣方的 scoreAd() 函式時出價後,記錄的主題的使用方式就和其他從競價設定傳遞的資料一樣。舉例來說,對於與偵測到的主題相符的廣告,賣方可能會想調高出價。

scoreAd(adMetadata, bid, auctionConfig, trustedScoringSignals, browserSignals, directFromSellerSignals) {
 
const sellerTopics = actionConfig.auctionSignals.topics;
 
// or corresponding key in sellerSignals
 
// use the topics values to score the ads
 
//...
}