SDK 이벤트(Node.js)
설명
SDK를 초기화할 때 options.events
개체는 이벤트 이름 키와 콜백 함수 값을 가진 선택적 개체입니다. SDK 내에서 발생하는 다양한 이벤트를 구독하는 데 사용할 수 있습니다. 예를 들어 clientReady
이벤트는 SDK에서 메서드 호출을 수행할 준비가 되었을 때 호출되는 콜백 함수와 함께 사용할 수 있습니다.
콜백 함수가 호출되면 이벤트 개체가 전달됩니다. 각 이벤트에는 이벤트 이름에 해당하는 type
이(가) 있습니다. 일부 이벤트에는 관련 정보가 포함된 추가 속성이 포함됩니다.
이벤트
이벤트 이름(유형)
설명
추가 이벤트 속성
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
6906415f-169c-422b-89d3-7118e147c4e3