快速入门 Target SDK

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

  • Node.js
  • Java
  • .NET
  • Python

步骤摘要

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

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

启用设备上决策可确保 A/B测试 活动以几乎零延迟的方式执行。 要启用此功能,请导航到 管理 > 实现 > 帐户详细信息 并启用 设备上决策 切换。

替代图像

NOTE
您必须拥有 管理员审批者 用户角色 启用或禁用 设备上决策 切换。

启用 设备上决策 切换, 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测试 活动

  1. 在 Target,导航到 活动 页面,然后选择 创建活动 > A/B测试.

    替代图像

  2. 创建A/B测试活动 模式窗口,保持默认Web选项处于选中状态(1),选择 表单 作为体验编辑器(2),选择 默认工作区 替换为 无属性限制(3),然后单击 下一个 (四)。

    替代图像

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

    替代图像

  4. 内容 部分,选择 创建JSON选件 (1)中进行归因、筛选、流程、流失等。

    替代图像

  5. JSON数据 在显示的文本框中,使用有效的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. 单击 下一个 (1)垫付予本公司股东,作为本 定位 活动创建步骤。

    替代图像

  7. 定位 为了简单起见,如下所示的步骤示例,“受众定位”(2)保留在“所有访客”的默认集中。 这意味着该活动未定位。 但是,请注意Adobe建议您始终将目标定位到生产活动的受众。 单击 下一个 (3)垫付予本公司股东,作为本 目标和设置 活动创建步骤。

    替代图像

  8. 目标和设置 步骤,设置 报表源Adobe Target (1)。 定义 目标量度 作为 转化,根据网站的转化量度指定详细信息(2)。 单击 保存并关闭 (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测试 活动

  1. 单击 激活 (1)激活您的 A/B测试 活动。

    note note
    NOTE
    您必须拥有 审批者发布者 用户角色 以执行此步骤。

    替代图像

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