SDK Events (Node.js)
説明
SDK🔗を初期化する場合、options.events オブジェクトは、イベント名キーとコールバック関数値を持つオプションのオブジェクトです。 SDK内で発生するさまざまなイベントの購読に使用できます。 例えば、clientReady イベントは、SDKがメソッド呼び出しの準備ができたときに呼び出されるコールバック関数と共に使用できます。
コールバック関数が呼び出されると、イベントオブジェクトが渡されます。 各イベントには、イベント名に対応するtypeがあります。 一部のイベントには、関連情報を含む追加のプロパティが含まれます。
Events
イベント名(タイプ)
説明
その他のイベントプロパティ
clientReady
アーティファクトがダウンロードされ、SDKが
getOffers呼び出しの準備ができたときに発行されます。 オンデバイス判定メソッドを使用する場合に推奨されます。artifactDownloadSucceeded
新しいアーティファクトがダウンロードされるたびに実行されます。
artifactPayload, artifactLocation
artifactDownloadFailed
アーティファクトのダウンロードに失敗するたびに実行されます。
artifactLocation、エラー
例
Node.js
const targetClient = TargetClient.create({
client: "acmeclient",
organizationId: "1234567890@AdobeOrg",
decisioningMethod: "on-device",
events: {
clientReady: onTargetClientReady,
artifactDownloadSucceeded: onArtifactDownloadSucceeded,
artifactDownloadFailed: onArtifactDownloadFailed
}
});
function onTargetClientReady() {
// make getOffers requests
targetClient.getOffers({...})
}
function onArtifactDownloadSucceeded(event) {
console.log(`The artifact was successfully downloaded from '${event.artifactLocation}'`);
// optionally do something with event.artifactPayload, like persist it
}
function onArtifactDownloadFailed(event) {
console.log(`The artifact failed to download from '${event.artifactLocation}' with the following error message: ${event.error.message}`);
}
recommendation-more-help
target-dev-help-dev