SDK イベント(Node.js)

説明

SDK を初期化する際、options.events オブジェクトは、イベント名キーとコールバック関数値を持つオプションのオブジェクトです。 SDK 内で発生する様々なイベントをサブスクライブするために使用できます。 例えば、clientReady イベントは、SDK がメソッド呼び出しの準備ができたときに呼び出されるコールバック関数と共に使用できます。

コールバック関数が呼び出されると、イベントオブジェクトが渡されます。 各イベントには、イベント名に対応する type があります。 一部のイベントには、関連情報を含む追加のプロパティが含まれています。

Events

イベント名(タイプ)
説明
その他のイベントプロパティ
clientReady
アーティファクトがダウンロードされ、SDK が getOffers 呼び出し用に準備されたときに発行されます。 オンデバイス判定方法を使用する場合に推奨されます。
artifactDownloadSuccessful
新しいアーティファクトがダウンロードされるたびに発行されます。
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
6906415f-169c-422b-89d3-7118e147c4e3