Edit in GitHubLog an issue

SDK Events

Description#

When initializing the SDK, the options.events object is an optional object with event name keys and callback function values. It can be used to subscribe to various events that occur within the SDK. For instance the clientReady event may be used with a callback function that will be invoked when the SDK is ready for method calls.

When the callback function is called, an event object is passed in. Each event has a type corresponding to the event name. And some events include additional properties with pertinent information.

Events#

Event Name (type)DescriptionAdditional Event Properties
clientReadyEmitted when the artifact has downloaded and the SDK is ready for getOffers calls. Recommended when using on-device decisioning method.
artifactDownloadSucceededEmitted each time a new artifact is downloaded.artifactPayload, artifactLocation
artifactDownloadFailedEmitted each time an artifact fails to download.artifactLocation, error

Example#

Copied to your clipboard
1const targetClient = TargetClient.create({
2 client: "acmeclient",
3 organizationId: "1234567890@AdobeOrg",
4 decisioningMethod: "on-device",
5 events: {
6 clientReady: onTargetClientReady,
7 artifactDownloadSucceeded: onArtifactDownloadSucceeded,
8 artifactDownloadFailed: onArtifactDownloadFailed
9 }
10});
11
12function onTargetClientReady() {
13 // make getOffers requests
14 targetClient.getOffers({...})
15}
16
17function onArtifactDownloadSucceeded(event) {
18 console.log(`The artifact was successfully downloaded from '${event.artifactLocation}'`);
19 // optionally do something with event.artifactPayload, like persist it
20}
21
22function onArtifactDownloadFailed(event) {
23 console.log(`The artifact failed to download from '${event.artifactLocation}' with the following error message: ${event.error.message}`);
24}
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.