Événements SDK (Node.js)
Description
Lors de l’initialisation du SDK, l’objet options.events est un objet facultatif avec des clés de nom d’événement et des valeurs de fonction de rappel. Il peut être utilisé pour vous abonner à divers événements qui se produisent dans le SDK. Par exemple, l’événement clientReady peut être utilisé avec une fonction de rappel appelée lorsque le SDK est prêt pour les appels de méthode.
Lorsque la fonction de rappel est appelée, un objet d’événement est transmis. Chaque événement possède un type correspondant au nom de l’événement. Certains événements incluent des propriétés supplémentaires avec des informations pertinentes.
Requête
Nom de l’événement (type)
Description
Propriétés d’événement supplémentaires
clientReady
Émis lorsque l’artefact a été téléchargé et que le SDK est prêt pour les appels
getOffers. Recommandé lors de l’utilisation de la méthode de prise de décision sur l’appareil.artifactDownloadSuccessfully
Émis chaque fois qu’un nouvel artefact est téléchargé.
artifactPayload, artifactLocation
artifactDownloadFailed
Émis chaque fois qu’un artefact ne parvient pas à être téléchargé.
artifactLocation, erreur
Exemple
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