快速入門 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 (破折號)
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),然後按一下 下一個 (4)。

    替代影像

  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