文件Target開發人員指南

adobe.target.sendNotifications(options)

最後更新: 2024年7月20日
  • 主題:

建立對象:

  • undefined

此函式會在體驗呈現時傳送通知給Target邊緣,而不需要使用adobe.target.applyOffer()或adobe.target.applyOffers()。

注意
此函數已在 at.js 2.1.0 中推出,且將適用於 2.1.0 以上的任何版本。
索引鍵類型必要?說明
consumerId字串無如果未提供,預設值為用戶端的全域 mbox。此機碼可用來產生用於 A4T 整合的補充資料 ID。
請求物件是請參閱下方的「要求」表格。
timeout數字無請求逾時。如果未指定,則會使用預設的 at.js 逾時。

請求

欄位名稱類型必要?限制說明
Request > notifications物件陣列是顯示內容、點擊選取器及/或已造訪的檢視或 mbox 的通知。
Request > notifications > address物件無
Request > notifications > address > url字串無觸發通知的來源 URL。
Request > notifications > address > referringUrl字串無觸發通知的來源引用 URL。
Request > notifications > parameters字串無

不允許在參數中使用下列名稱:

  • orderId
  • orderTotal
  • productPurchasedIds

考慮以下事項:

  • 上限為 50 個參數。
  • 參數名稱不得空白。
  • 參數名稱長度上限為 128。
  • 參數名稱的開頭不得為「設定檔」。
  • 參數值長度上限為 5000。
Request > notifications > profileParameters字串無

不允許在參數中使用下列名稱:

  • orderId
  • orderTotal
  • productPurchasedIds

考慮以下事項:

  • 上限為 50 個參數。
  • 參數名稱不得空白。
  • 參數名稱長度上限為 128。
  • 參數名稱的開頭不得為「設定檔」。
  • 參數值長度上限為 5000。
Request > notifications > order物件無說明訂單詳細資料的物件。

Request > notifications > order

id

字串無<= 250 個字元。訂購 ID.

Request > notifications > order

total

字串無>= 0訂購總計.

Request > notifications > order

purchasedProductIds

字串陣列無
  • 不允許使用任何空白值。
  • 每個產品 ID 長度上限為 50。
  • 產品 ID,以逗號分隔並串連,總長度不得超過 250。
訂購產品 ID。
Request > notifications > product物件無
Request > notifications > product > id字串無<= 128 個字元;不得空白。產品 ID.
Request > notifications > product > categoryId字串無<= 128 個字元;不得空白。類別 ID。
Request > notifications > id字串是<= 200 個字元。回應中將傳回通知 ID,且會包含已成功處理的通知。
Request > notifications > impressionId字串無<= 128 個字元。Impression ID 可用來拼接 (連結) 目前的通知與先前的通知或執行要求。在兩者彼此相符的情況下,第二個和其他後續要求將不會對活動或體驗產生新曝光次數。
Request > notifications > type字串是支援「按一下」或「顯示」。通知類型。
Request > notifications > timestamp數字<int64>是自 UNIX 紀元以來經過時間之通知的時間戳記 (以毫秒為單位)。
Request > notifications > tokens字串陣列是根據通知類型,顯示內容或點擊選取器的 Token 清單。
Request > notifications > mbox物件無mbox 的通知。

Request > notifications > mbox

name

字串無

不允許使用任何空白值。

允許的字元:請參閱此表格後的備註。

mBox 名稱。

Request > notifications > mbox

state

字串無mbox 狀態 Token。
Request > notifications > view物件無

Request > notifications > view

id

整數 <int64>無檢視 ID。透過檢視 API 建立檢視時,已指派給檢視的 ID。

Request > notifications > view

name

字串無<= 128 個字元。檢視的名稱。

Request > notifications > view

key

字串無<= 512 個字元。檢視金鑰。已透過 API 使用檢視設定的金鑰。

Request > notifications > view

state

字串無檢視狀態 Token。

注意: Request > notifications > mbox > name不允許​ 下列字元:

- '-, ./=`:;&!@#$%^&*()+|?~[]{}'

呈現預先擷取 mbox 後的 sendNotifications() 呼叫

function createTokens(options) {
  return options.map(e => e.eventToken);
}

function createNotification(mbox, type, tokens) {
  const id = 11111; // here we should use a random ID like UUID
  const timestamp = Date.now();
  const { name, state, parameters, profileParameters, order, product } = mbox;
  const result = {
    id,
    type,
    timestamp,
    parameters,
    profileParameters,
    order,
    product
  };

  result.mbox = { name, state };
  result.tokens = tokens;

  return result;
}

adobe.target.getOffers({
  request: {
    prefetch: {
      mboxes: [
        {
          index: 0,
          name: "a1-serverside-ab"
        }
      ]
    }
  }
})
.then(response => {
  const mboxes = response.prefetch.mboxes;
  const notifications = mboxes.map(mbox => {
    const type = "display";
    const tokens = createTokens(mbox.options);

    return createNotification(mbox, type, tokens);
  });

  adobe.target.sendNotifications({
    request: { notifications }
  });
})
NOTE
如果您使用Adobe Analytics、getOffers()且僅具有預先擷取,而且使用sendNotifications(),則必須在執行sendNotifications()之後觸發Analytics要求。 其目的在於確保sendNotifications()產生的SDID符合傳送給Analytics和Target的SDID。
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3