Downloading, storing, and updating the rule artifact automatically via the Adobe Target SDK
This approach is best when you are able to initialize the Adobe Target SDK at the same time you initialize and start your web server. The rule artifact will be downloaded by the Adobe Target SDK and cached into memory before your web server application starts serving requests. Once your web application is up and running, all Adobe Target decisions will be executed using the in-memory rule artifact. The cached rule artifact will be updated based on the pollingInterval
you specify during the SDK initialization step.
Summary of steps
- Install the SDK
- Initialize the SDK
- Store and Use the Rule Artifact
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: { clientReady: startWebServer } }; const TargetClient = TargetClient.create(CONFIG); function startWebServer() { //Adobe Target SDK has now downloaded the JSON Artifacts and is available in the memory. //You can start your web server now to serve requests now. }
Java
code language-javascript line-numbers ClientConfig config = ClientConfig.builder() .client("<you target client code>") .organizationId("<your EC org id>") .build(); TargetClient targetClient = TargetClient.create(config);
-
Both client and organizationId can be retrieved from Adobe Target by navigating to Administration > Implementation, as shown here.
3. Store and use the rule artifact
You do not need to manage the rule artifact yourself and calling the SDK methods should be straightforward.
code language-javascript line-numbers |
---|
|
code language-java line-numbers |
---|
|
TargetClient
object holds a reference to the in-memory rule artifact. When you use this object for invoking standard SDK methods, it uses the in-memory rule artifact for decisioning. If your application is structured such that you need to call the SDK methods in files other than the one that initializes and listens to client requests, and if those files do not have access to the TargetClient object, then you can download the JSON payload and store it in a local JSON file to be consumed on other files, which need to initialize the SDK. This is explained in the next section, regarding downloading the rule artifact using a JSON payload.Here is an example that starts a web application after initializing the Adobe Target SDK.
code language-javascript line-numbers |
---|
|
code language-java line-numbers |
---|
|