Het regelartefact downloaden, opslaan en bijwerken via JSON-payload
Deze aanpak is het best als uw toepassing op een manier gestructureerd is die vereist dat SDK op elk dossier wordt geïnitialiseerd waarin het methodes SDK gebruikt. Voordat uw webtoepassing de JSON-payload van het regelartefact tijdens de SDK-initialisatie kan gebruiken, moet u ervoor zorgen dat de JSON-payload wordt gedownload en beschikbaar is voor uw toepassing.
Overzicht van de stappen
- De SDK installeren
- De SDK initialiseren
- Opslaan en JSON Payload gebruiken
1. Installeer de SDK
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|
2. Initialiseer de SDK
-
Importeer eerst de SDK. Importeer naar hetzelfde bestand waaruit u het opstarten van de server kunt beheren.
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;
-
Om SDK te vormen, gebruik creeer methode.
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);
-
Zowel client als
organizationId
kan worden opgehaald van Adobe Targetdoor naar Administration > Implementation, zoals u hier ziet.<!— Voeg image-client-code.png toe —>
3. Sla de JSON-lading op en gebruik deze
Het mechanisme dat u gebruikt om de JSON-payload op te slaan, is afhankelijk van uw systeemarchitectuur. U kunt een lokaal bestand, een database of een systeem voor het in cache plaatsen van geheugenobjecten gebruiken, zoals Memcached. U moet deze JSON kunnen lezen vanuit uw toepassing voor consumptie. In deze handleiding gebruiken we een lokaal bestand als opslaglocatie.
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|
Hier ziet u een voorbeeld van de JSON-functionaliteit voor het initialiseren van de lading.
code language-javascript line-numbers |
---|
|
code language-javascript line-numbers |
---|
|