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 トグルを有効にします。

alt画像

NOTE
On-Device Decisioning​切り替えを有効または無効にするには、Admin​または​Approver ​ ユーザー役割が必要です。

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​を選択します。

    alt画像

  2. Create A/B Test Activity モーダルで、デフォルトのWeb オプションを選択したままにし(1)、エクスペリエンスコンポーザーとして​ Form ​を選択し(2)、No Property Restrictions (3)で​ Default Workspace ​を選択し、Next (4)をクリックします。

    alt画像

  3. アクティビティ作成の​Experiences ステップで、アクティビティの名前(1)を入力し、Add Experience (2)をクリックして2つ目のエクスペリエンスであるエクスペリエンス Bを追加します。 選択した場所の名前を入力します(3)。 例えば、ondevice-featureflagまたはhomepage-addtocart-featureflagは、機能フラグテストの宛先を示す場所名です。 次の例では、ondevice-featureflagはエクスペリエンス Bに対して定義された場所です。必要に応じて、オーディエンスの絞り込み(4)を追加して、アクティビティへの選定を制限できます。

    alt画像

  4. 同じページの「CONTENT」セクションで、図に示すように、ドロップダウン(1)で「Create JSON Offer」を選択します。

    alt画像

  5. 表示される​JSON Data テキストボックスに、有効なJSON オブジェクト (2)を使用して、各エクスペリエンス (1)の機能フラグ変数を入力します。

    エクスペリエンス Aの機能フラグ変数を入力します。

    alt画像

    (エクスペリエンス Aのサンプル JSON、上記)

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

    エクスペリエンス Bの機能フラグ変数を入力します。

    alt画像

    (Experience Bのサンプル JSON、上記)

    code language-json line-numbers
    
    {
       "enabled" : true,
       "flag" : "expB"
    }
    
  6. Next (1)をクリックして、アクティビティ作成の​Targeting ステップに進みます。

    alt画像

  7. 以下に示す​Targeting ステップの例では、簡単に説明するために、オーディエンスターゲティング (2)はすべての訪問者のデフォルトセットに残っています。 つまり、活動はターゲット化されていません。 ただし、Adobeでは、実稼動アクティビティに対してオーディエンスを常にターゲティングすることをお勧めします。 Next (3)をクリックして、アクティビティ作成の​Goals & Settings ステップに進みます。

    alt画像

  8. Goals & Settings ステップで、Reporting Source​を​Adobe Target (1)に設定します。 Goal Metric​を​ Conversion ​として定義し、サイトのコンバージョン指標(2)に基づいて詳細を指定します。 アクティビティを保存するには、Save & Close (3)をクリックします。

    alt画像

​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
    この手順を実行するには、Approver​または​Publisher ​ ユーザーの役割が必要です。

    alt画像

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