Downloading, storing, and updating the rule artifact via JSON payload
This approach is best if your application is structured in a way that requires the SDK to be initialized on each file in which it uses SDK methods. Before your web application can use the JSON payload of the rule artifact during SDK initialization, you should ensure the JSON payload is downloaded and is available for your application to use.
Summary of steps
- Install the SDK
- Initialize the SDK
- Store and Use the JSON Payload
1. Install the SDK
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|
2. Initialize the SDK
-
First, import the SDK. Import to the same file from which you can control your server start-up.
Node.js
code language-javascript line-numbers const TargetClient = require("@adobe/target-nodejs-sdk");
Java
code language-javascript line-numbers import com.adobe.target.edge.client.ClientConfig; import com.adobe.target.edge.client.TargetClient;
-
To configure the SDK, use the create method.
Node.js
code language-javascript line-numbers const CONFIG = { client: "<your target client code>", organizationId: "your EC org id", decisioningMethod: "on-device", pollingInterval : 300000, events: { artifactDownloadSucceeded: onArtifactDownloadSucceeded, artifactDownloadFailed: onArtifactDownloadFailed } }; const TargetClient = TargetClient.create(CONFIG); function onArtifactDownloadSucceeded(event) { //Adobe Target SDK has now downloaded the JSON Artifact/Payload console.log(event.artifactLocation) // Location from where the Artifact is downloaded. console.log(event.artifactPayload) // JSON Payload which we can store locally. } function onArtifactDownloadFailed(event) { //Adobe Target SDK has failed to download the JSON Artifact/Payload. console.log(event.artifactLocation) // Location from where the Artifact is downloaded. console.log(event.error.message) // Error message }
Java
code language-javascript line-numbers package com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler; ClientConfig config = ClientConfig.builder() .client("<you target client code>") .organizationId("<your EC org id>") .onDeviceDecisioningHandler( new OnDeviceDecisioningHandler() { void onDeviceDecisioningReady() { // On-Device Decision is ready. } void artifactDownloadSucceeded(byte[] artifactData) { // Store artifactData to local disk. // ... } } ) .build(); TargetClient targetClient = TargetClient.create(config);
-
Both client and
organizationId
can be retrieved from Adobe Targetby navigating to Administration > Implementation, as shown here.
3. Store and rse the JSON payload
The mechanism you use to store the JSON payload depends on your system architecture. You can use a local file, a database, or a memory object caching system such as Memcached. You need to be able to read this JSON from your application for consumption. In this guide, we use a local file as the storage.
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|
Here is an example demonstrating the JSON payload-initializing capability.
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|