說明
當初始化SDK時,options.events
物件為具有事件名稱索引鍵和回呼函式值的選用物件。 可用來訂閱SDK內發生的各種事件。 例如,clientReady
事件可與回呼函式搭配使用,當SDK準備好進行方法呼叫時,將會叫用該回呼函式。
呼叫回呼函式時,事件物件會傳入。 每個事件都有一個type
對應至事件名稱。 有些事件包含其他屬性以及相關資訊。
事件
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}`);
}