文件Target開發人員指南

取得屬性(Node.js)

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

建立對象:

  • 開發人員

說明

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