文档Target开发人员指南

adobe.target.sendNotifications(options)

最近更新: 2024年7月20日
  • 主题:

创建对象:

  • undefined

在不使用adobe.target.applyOffer()或adobe.target.applyOffers()呈现体验时,此函数会向Target边缘发送通知。

注意
此函数已在 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。
  • 参数名称不应以“profile”开头。
  • 参数值的最大长度为 5000。
Request > notifications > profileParameters字符串否

参数不允许使用以下名称:

  • orderId
  • orderTotal
  • productPurchasedIds

请考虑以下事项:

  • 参数上限为 50 个。
  • 参数名称不应为空。
  • 参数名称的最大长度为 128。
  • 参数名称不应以“profile”开头。
  • 参数值的最大长度为 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 个字符。展示 ID 用于将当前通知与先前的通知或执行请求拼合(链接)到一起。如果两者匹配,则第二个和其他后续请求不会生成活动或体验的新展示。
Request > notifications > type字符串是支持“click”或“display”。通知类型。
Request > notifications > timestamp数值<int64>是通知的时间戳(以自 UNIX 纪元以来所经过的毫秒数为单位)。
Request > notifications > tokens字符串数组是基于通知类型的已显示内容或已点击选择器的令牌列表。
Request > notifications > mbox对象否有关 mbox 的通知。

Request > notifications > mbox

name

字符串否

不允许使用空值。

允许的字符:请参阅此表后面的注释。

mbox 名称。

Request > notifications > mbox

state

字符串否mbox 状态令牌。
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

字符串否视图状态令牌。

注意: 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