Guida introduttiva a Target SDK

Per iniziare, ti invitiamo a creare la tua prima attività di flag di funzionalità decisioning sul dispositivo nella lingua desiderata:

  • Node.js
  • Java
  • .NET
  • Python

Riepilogo dei passaggi

  1. Abilitare il decisioning sul dispositivo per la tua organizzazione
  2. Installare SDK
  3. Inizializzare SDK
  4. Configurare i flag di funzionalità in un’attività Adobe Target Test A/B
  5. Implementare ed eseguire il rendering della funzione nell’applicazione
  6. Implementa il tracciamento degli eventi nell’applicazione
  7. Attiva l’attività Test A/B

​1. Abilitare il decisioning sul dispositivo per la tua organizzazione

L’abilitazione del decisioning sul dispositivo garantisce che un’attività Test A/B venga eseguita con latenza prossima allo zero. Per abilitare questa funzione, passa a Amministrazione > Implementazione > Dettagli account e abilita l’interruttore Decisioning sul dispositivo.

Alt immagine

NOTE
Per abilitare o disabilitare l'opzione Decisioning sul dispositivo, è necessario avere il ruolo Amministratore o Approvatore utente.

Dopo aver attivato l’interruttore Decisioning sul dispositivo, Adobe Target inizia a generare artefatti regola per il client.

​2. Installare SDK

Per Node.js, Java e Python, esegui il seguente comando nella directory del progetto nel terminale. Per .NET, aggiungerlo come dipendenza installandolo da NuGet.

Node.js (NPM)
code language-js line-numbers
npm i @adobe/target-nodejs-sdk -P
Java (Maven)
code language-javascript line-numbers
<dependency>
   <groupId>com.adobe.target</groupId>
   <artifactId>java-sdk</artifactId>
   <version>2.0</version>
</dependency>
.NET (Bash)
code language-bash line-numbers
dotnet add package Adobe.Target.Client
Python (pip)
code language-python line-numbers
pip install target-python-sdk

​3. Inizializzare SDK

L’artefatto della regola viene scaricato durante il passaggio di inizializzazione di SDK. Puoi personalizzare il passaggio di inizializzazione per determinare come viene scaricato e utilizzato l’artefatto.

Node.js
code language-js line-numbers
const TargetClient = require("@adobe/target-nodejs-sdk");

const CONFIG = {
   client: "<your target client code>",
   organizationId: "your EC org id",
   decisioningMethod: "on-device",
   events: {
      clientReady: targetClientReady
      }
};

const tClient = TargetClient.create(CONFIG);

function targetClientReady() {
   //Adobe Target SDK has now downloaded the JSON artifact locally, which contains the activity details.
   //We will see how to use the artifact here very soon.
}
Java (Maven)
code language-javascript line-numbers
ClientConfig config = ClientConfig.builder()
   .client("testClient")
   .organizationId("ABCDEF012345677890ABCDEF0@AdobeOrg")
   .build();
TargetClient targetClient = TargetClient.create(config);
.NET (C#)
code language-csharp line-numbers
var targetClientConfig = new TargetClientConfig.Builder("testClient", "ABCDEF012345677890ABCDEF0@AdobeOrg")
   .Build();
this.targetClient.Initialize(targetClientConfig);
Python
code language-python line-numbers
from target_python_sdk import TargetClient

def target_client_ready():
   # Adobe Target SDK has now downloaded the JSON artifact locally, which contains the activity details.
   # We will see how to use the artifact here very soon.

CONFIG = {
   "client": "<your target client code>",
   "organization_id": "your EC org id",
   "decisioning_method": "on-device",
   "events": {
      "client_ready": target_client_ready
   }
}

target_client = TargetClient.create(CONFIG)

​4. Configurare i flag di funzionalità in un’attività Adobe Target Test A/B

  1. In Target, passa alla pagina Attività, quindi seleziona Crea attività > Test A/B.

    Alt immagine

  2. Nella finestra modale Crea attività test A/B, lascia selezionata l’opzione Web predefinita (1), seleziona Modulo come Compositore esperienza (2), seleziona Workspace predefinito con Nessuna restrizione proprietà(3), quindi fai clic su Avanti (4).

    Alt immagine

  3. Nel passaggio Esperienze della creazione dell’attività, fornisci un nome per l’attività (1) e aggiungi una seconda esperienza, Esperienza B, facendo clic su Aggiungi esperienza (2). Immettere il nome della posizione desiderata (3). Ad esempio, ondevice-featureflag o homepage-addtocart-featureflag sono nomi di posizione che indicano le destinazioni per il test dei flag di funzionalità. Nell’esempio seguente, ondevice-featureflag è la posizione definita per l’Esperienza B. Facoltativamente, puoi aggiungere Perfezionamenti del pubblico (4) per limitare la qualifica all’attività.

    Alt immagine

  4. Nella sezione CONTENT sulla stessa pagina, seleziona Crea offerta JSON nel menu a discesa (1) come mostrato.

    Alt immagine

  5. Nella casella di testo Dati JSON visualizzata, digita le variabili del flag di funzione per ogni esperienza (1), utilizzando un oggetto JSON valido (2).

    Immetti le variabili dei flag di funzione per l’Esperienza A.

    Alt immagine

    (JSON di esempio per l’esperienza A, superiore)

    code language-json line-numbers
    
    {
       "enabled" : true,
       "flag" : "expA"
    }
    

    Immetti le variabili dei flag di funzione per l’Esperienza B.

    Alt immagine

    (JSON di esempio per l’esperienza B, superiore)

    code language-json line-numbers
    
    {
       "enabled" : true,
       "flag" : "expB"
    }
    
  6. Fai clic su Avanti (1) per passare al passaggio Targeting della creazione di attività.

    Alt immagine

  7. Nell’esempio del passaggio Targeting mostrato di seguito, il Targeting del pubblico (2) rimane sul set predefinito di Tutti i visitatori, per semplicità. Ciò significa che l’attività non è targetizzata. Tuttavia, tieni presente che Adobe consiglia di indirizzare sempre il pubblico alle attività di produzione. Fai clic su Avanti (3) per passare al passaggio Obiettivi e impostazioni della creazione dell’attività.

    Alt immagine

  8. Nel passaggio Obiettivi e impostazioni, impostare Reporting Source su Adobe Target (1). Definisci la metrica obiettivo come Conversione, specificando i dettagli in base alle metriche di conversione del sito (2). Fai clic su Salva e chiudi (3) per salvare l’attività.

    Alt immagine

​5. Implementare ed eseguire il rendering della funzione nell’applicazione

Dopo aver impostato le variabili dei flag di funzionalità in Target, modificare il codice dell’applicazione per utilizzarle. Ad esempio, dopo aver ottenuto il flag di funzione nell’applicazione, puoi utilizzarlo per abilitare le funzioni ed eseguire il rendering dell’esperienza per la quale il visitatore si è qualificato.

Node.js
code language-js line-numbers
//... Code removed for brevity
​
let featureFlags = {};
​
function targetClientReady() {
   tClient.getAttributes(["ondevice-featureflag"]).then(function(response) {
      const featureFlags = response.asObject("ondevice-featureflag");
      if(featureFlags.enabled && featureFlags.flag !== "expA") { //Assuming "expA" is control
         console.log("Render alternate experience" + featureFlags.flag);
      }
      else {
         console.log("Render default experience");
      }
   });
}
Java (Maven)
code language-javascript line-numbers
MboxRequest mbox = new MboxRequest().name("ondevice-featureflag").index(0);
TargetDeliveryRequest request = TargetDeliveryRequest.builder()
   .context(new Context().channel(ChannelType.WEB))
   .execute(new ExecuteRequest().mboxes(Arrays.asList(mbox)))
   .build();
Attributes attributes = targetClient.getAttributes(request, "ondevice-featureflag");
String flag = attributes.getString("ondevice-featureflag", "flag");
.NET (C#)
code language-csharp line-numbers
var mbox = new MboxRequest(index: 0, name: "ondevice-featureflag");
var deliveryRequest = new TargetDeliveryRequest.Builder()
   .SetContext(new Context(ChannelType.Web))
   .SetExecute(new ExecuteRequest(mboxes: new List<MboxRequest> { mbox }))
   .Build();
var attributes = targetClient.GetAttributes(request, "ondevice-featureflag");
var flag = attributes.GetString("ondevice-featureflag", "flag");
Python
code language-python line-numbers
# ... Code removed for brevity

feature_flags = {}

def target_client_ready():
   attribute_provider = target_client.get_attributes(["ondevice-featureflag"])
   feature_flags = attribute_provider.as_object(mbox_name="ondevice-featureflag")
   if feature_flags.get("enabled") and feature_flags.get("flag") != "expA": # Assuming "expA" is control
      print("Render alternate experience {}".format(feature_flags.get("flag")))
   else:
      print("Render default experience")

​6. Implementa il tracciamento aggiuntivo per gli eventi nell’applicazione

Facoltativamente, puoi inviare eventi aggiuntivi per il tracciamento delle conversioni utilizzando la funzione sendNotification().

Node.js
code language-js line-numbers
//... Code removed for brevity
​
//When a conversion happens
TargetClient.sendNotifications({
   targetCookie,
   "request" : {
      "notifications" : [
      {
         type: "display",
         timestamp : Date.now(),
         id: "conversion",
         mbox : {
            name : "orderConfirm"
         },
         order : {
            id: "BR9389",
            total : 98.93,
            purchasedProductIds : ["J9393", "3DJJ3"]
         }
      }
      ]
   }
})
Java (Maven)
code language-javascript line-numbers
Notification notification = new Notification();
notification.setId("conversion");
notification.setImpressionId(UUID.randomUUID().toString());
notification.setType(MetricType.DISPLAY);
notification.setTimestamp(System.currentTimeMillis());
Order order = new Order("BR9389");
order.total(98.93);
order.purchasedProductIds(["J9393", "3DJJ3"]);
notification.setOrder(order);

TargetDeliveryRequest notificationRequest =
   TargetDeliveryRequest.builder()
      .context(new Context().channel(ChannelType.WEB))
      .notifications(Collections.singletonList(notification))
      .build();

NotificationDeliveryService notificationDeliveryService = new NotificationDeliveryService();
notificationDeliveryService.sendNotification(notificationRequest);
.NET (C#)
code language-csharp line-numbers
var order = new Order
{
   Id = "BR9389",
   Total = 98.93M,
   PurchasedProductIds = new List<string> { "J9393", "3DJJ3" },
};
​
var notification = new Notification
{
   Id = "conversion",
   ImpressionId = Guid.NewGuid().ToString(),
   Type = MetricType.Display,
   Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
   Order = order,
};
​
var notificationRequest = new TargetDeliveryRequest.Builder()
   .SetContext(new Context(ChannelType.Web))
   .SetNotifications(new List<Notification> {notification})
   .Build();
​
targetClient.SendNotifications(notificationRequest);
Python
code language-python line-numbers
# ... Code removed for brevity

# When a conversion happens
notification_mbox = NotificationMbox(name="orderConfirm")
order = Order(id="BR9389, total=98.93, purchased_product_ids=["J9393", "3DJJ3"])
notification = Notification(
   id="conversion",
   type=MetricType.DISPLAY,
   timestamp=1621530726000,  # Epoch time in milliseconds
   mbox=notification_mbox,
   order=order
)
notification_request = DeliveryRequest(notifications=[notification])

target_client.send_notifications({
   "target_cookie": target_cookie,
   "request" : notification_request
})

​7. Attiva l’attività Test A/B

  1. Fai clic su Attiva (1) per attivare l’attività Test A/B.

    note
    NOTE
    Per eseguire questo passaggio, è necessario disporre del ruolo Approvatore o Editore utente.

    Alt immagine

recommendation-more-help
target-dev-help-dev