取得屬性(Node.js)
說明
getAttributes()
是用來從Target擷取實驗與個人化體驗,以及擷取屬性值。
方法
getAttributes
TargetClient.getAttributes(mboxNames: Array, options: Object): Promise
參數
名稱
類型
必要
預設值
mboxNames
陣列
是
無
options
物件
無
無
Promise
TargetClient.getAttributes()
傳回的Promise
會使用下列方法解析物件:
方法
傳回類型
說明
getValue(mboxName, key)
任何
傳回指定mbox名稱和屬性索引鍵的值
asObject(mboxName)
物件
傳回具有索引鍵值配對的簡單json物件
範例
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