Target SDK快速入门

为了启动并运行,我们鼓励您以您选择的语言创建您的第一个设备上决策功能标记活动:

  • Node.js
  • Java
  • .NET
  • Python

步骤摘要

  1. 为您的组织启用设备上决策
  2. 安装SDK
  3. 初始化SDK
  4. 在Adobe Target A/B Test活动中设置功能标记
  5. 在应用程序中实施和渲染功能
  6. 对应用程序中的事件实施跟踪
  7. 激活您的A/B Test活动

1.为您的组织启用设备上决策

启用设备上决策可确保在几乎零延迟的情况下执行A/B Test活动。 要启用此功能,请导航到​ Administration > Implementation > Account details ​并启用​ On-Device Decisioning ​切换开关。

替代图像

NOTE
您必须具有​ Admin ​或​ Approver 用户角色才能启用或禁用​ On-Device Decisioning ​切换。

启用​ On-Device Decisioning ​切换后,Adobe Target开始为您的客户端生成规则工件

2.安装SDK

对于Node.js、Java和Python,请在终端的项目目录中运行以下命令。 对于.NET,通过从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.初始化SDK

规则工件将在SDK初始化步骤中下载。 您可以自定义初始化步骤以确定如何下载和使用工件。

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.在Adobe Target A/B Test活动中设置功能标记

  1. 在Target中,导航到​ Activities ​页面,然后选择​ Create Activity > A/B test

    替代图像

  2. 在​ Create A/B Test Activity ​模式中,保持默认Web选项处于选中状态(1),选择​ Form ​作为体验编辑器(2),选择带有​ No Property Restrictions(3)的​ Default Workspace,然后单击​ Next (4)。

    替代图像

  3. 在活动创建的​ Experiences ​步骤中,提供活动的名称(1)并单击​ Add Experience (2)以添加第二个体验,即体验B。 输入您选择的位置名称(3)。 例如,ondevice-featureflaghomepage-addtocart-featureflag是指示功能标志测试目标的位置名称。 在下面显示的示例中,ondevice-featureflag是为体验B定义的位置。或者,您可以添加受众细化(4)以限制活动的资格。

    替代图像

  4. 在同一页面的​ CONTENT ​部分中,从下拉列表(1)中选择​ Create JSON Offer,如图所示。

    替代图像

  5. 在出现的​ JSON Data ​文本框中,使用有效的JSON对象(2)为每个体验(1)键入功能标志变量。

    输入体验A的功能标志变量。

    替代图像

    (以上体验A的示例JSON)

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

    输入体验B的功能标志变量。

    替代图像

    (以上体验B的示例JSON)

    code language-json line-numbers
       {
       "enabled" : true,
       "flag" : "expB"
    }
    
  6. 单击​ Next (1)以进入活动创建的​ Targeting ​步骤。

    替代图像

  7. 为了简单起见,在下面显示的​ Targeting ​步骤示例中,“受众定位”(2)保留在“所有访客”的默认集中。 这意味着该活动未定位。 但是,请注意Adobe建议您始终将目标定位到生产活动的受众。 单击​ Next (3)以进入活动创建的​ Goals & Settings ​步骤。

    替代图像

  8. 在​ Goals & Settings ​步骤中,将​ Reporting Source ​设置为​ Adobe Target (1)。 将​ Goal Metric ​定义为​ Conversion,根据您网站的转化量度指定详细信息(2)。 单击​ Save & Close (3)以保存活动。

    替代图像

5.在应用程序中实施并渲染功能

在Target中设置功能标志变量后,请修改应用程序代码以使用它们。 例如,在应用程序中获取功能标志后,您可以使用该标志启用功能并呈现访客符合条件的体验。

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.对应用程序中的事件实施其他跟踪

或者,您也可以使用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.激活您的A/B Test活动

  1. 单击​ Activate (1)以激活您的A/B Test活动。

    note note
    NOTE
    您必须具有​ Approver ​或​ Publisher 用户角色才能执行此步骤。

    替代图像

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