Getting Started with Target SDKs

In order to get up and running, we encourage you to create your first on-device decisioning feature flag activity in the language of your choice:

  • Node.js
  • Java
  • .NET
  • Python

Summary of steps

  1. Enable on-device decisioning for your organization
  2. Install the SDK
  3. Initialize the SDK
  4. Set up the feature flags in an Adobe Target A/B Test activity
  5. Implement and render the feature in your application
  6. Implement tracking for events in your application
  7. Activate your A/B Test activity

1. Enable on-device decisioning for your organization

Enabling on-device decisioning ensures an A/B Test activity is executed at near-zero latency. To enable this feature, navigate to Administration > Implementation > Account details and enable the On-Device Decisioning toggle.

alt image

NOTE
You must have the Admin or Approver user role to enable or disable the On-Device Decisioning toggle.

After enabling the On-Device Decisioning toggle, Adobe Target begins generating rule artifacts for your client.

2. Install the SDK

For Node.js, Java, and Python, run the following command in your project directory in the terminal. For .NET, add it as a dependency by installing from 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. Initialize the SDK

The rule artifact is downloaded during the SDK initialization step. You can customize the initialization step to determine how the artifact is downloaded and used.

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. Set up the feature flags in an Adobe Target A/B Test activity

  1. In Target, navigate to the Activities page, then select Create Activity > A/B test.

    alt image

  2. In the Create A/B Test Activity modal, leave the default Web option selected (1), select Form as your experience composer (2), select Default Workspace with No Property Restrictions(3), then click Next (4).

    alt image

  3. In the Experiences step of activity creation, provide a name for your activity (1) and add a second experience, Experience B, by clicking Add Experience (2). Enter the location name of your choice (3). For example, ondevice-featureflag or homepage-addtocart-featureflag are location names indicating the destinations for feature flag testing. In the example shown below, ondevice-featureflag is the location defined for Experience B. Optionally, you may add Audience Refinements (4) to restrict qualification to the activity.

    alt image

  4. In the CONTENT section on the same page, select Create JSON Offer in the drop-down (1) as shown.

    alt image

  5. In the JSON Data text box that appears, type your feature flag variables for each experience (1), using a valid JSON object (2).

    Enter the feature flag variables for Experience A.

    alt image

    (Sample JSON for Experience A, above)

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

    Enter the feature flag variables for Experience B.

    alt image

    (Sample JSON for Experience B, above)

    code language-json line-numbers
       {
       "enabled" : true,
       "flag" : "expB"
    }
    
  6. Click Next (1) to advance to the Targeting step of activity creation.

    alt image

  7. In the Targeting step example shown below, Audience Targeting (2) remains on the default set of All Visitors, for simplicity. This means the activity is untargeted. However, note Adobe recommends you always target your audiences for production activities. Click Next (3) to advance to the Goals & Settings step of activity creation.

    alt image

  8. In the Goals & Settings step, set Reporting Source to Adobe Target (1). Define the Goal Metric as Conversion, specifying the details based on your site’s conversion metrics (2). Click Save & Close (3) to save the activity.

    alt image

5. Implement and render the feature in your application

After setting up the feature flag variables in Target, modify your application code to use them. For example, after getting the feature flag in the application, you can use it to enable features and render the experience for which the visitor qualified.

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. Implement additional tracking for events in your application

Optionally, you can send additional events for tracking conversions using the sendNotification() function.

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. Activate your A/B Test activity

  1. Click Activate (1) to activate your A/B Test activity.

    note note
    NOTE
    You must have the Approver or Publisher user role to perform this step.

    alt image

recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3