文档Target开发人员指南

获取属性(Node.js)

2024年7月20日
  • 主题:

创建对象:

  • undefined

描述

getAttributes()用于从Target获取试验性和个性化体验并提取属性值。

方法

getAttributes

TargetClient.getAttributes(mboxNames: Array, options: Object): Promise

参数

名称类型必需默认
mboxNames数组是无
options对象否无

Promise

TargetClient.getAttributes()返回的Promise使用以下方法解析对象:

方法返回类型描述
getValue(mboxName, key)“任一”返回指定mbox名称和属性键的值
asObject(mboxName)对象返回具有键值对的简单json对象
getResponse()getOffers响应返回getOffers通常返回的响应对象

示例

Node.js

const TargetClient = require("@adobe/target-nodejs-sdk");
const CONFIG = {
  client: "acmeclient",
  organizationId: "1234567890@AdobeOrg"
};

const targetClient = TargetClient.create(CONFIG);
const offerAttributes = await targetClient.getAttributes(["demo-engineering-flags"]);


//returns just the value of searchProviderId from the mbox offer
const searchProviderId = offerAttributes.getValue("demo-engineering-flags", "searchProviderId");

//returns a simple JSON object representing the mbox offer
const engineeringFlags = offerAttributes.asObject("demo-engineering-flags");

//  the value of engineeringFlags looks like this
//  {
//      "cdnHostname": "cdn.cloud.corp.net",
//      "searchProviderId": 143,
//      "hasLegacyAccess": false
//  }

const assetUrl = `http://${engineeringFlags.cdnHostname}/path/to/asset`;
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3