Target SDK の概要
- トピック:
- APIs/SDKs
作成対象:
- 開発者
動作を開始するには、最初の オンデバイス判定機能フラグアクティビティを選択した言語で作成することをお勧めします。
- Node.js
- Java
- .NET
- Python
手順の概要
- 組織のオンデバイス判定を有効にする
- SDK のインストール
- SDK の初期化
- Adobe Target A/B Test アクティビティの機能フラグの設定
- アプリケーションでの機能の実装とレンダリング
- アプリケーションにイベントのトラッキングを実装
- A/B Test アクティビティのアクティベート
1.組織のオンデバイス判定を有効にする
オンデバイス判定を有効にすると、A/B Test アクティビティがほぼゼロの待ち時間で実行されるようになります。 この機能を有効にするには、Administration / Implementation / Account details に移動し、「On-Device Decisioning」トグルを有効にします。
「On-Device Decisioning」切替スイッチを有効 Adobe Target すると、クライアントの ルールアーティファクトの生成を開始します。
2. SDK をインストールする
Node.js、Java および Python の場合は、ターミナルのプロジェクトディレクトリで次のコマンドを実行します。 .NET の場合は、NuGet からインストールして、依存関係として追加します。
npm i @adobe/target-nodejs-sdk -P
<dependency>
<groupId>com.adobe.target</groupId>
<artifactId>java-sdk</artifactId>
<version>2.0</version>
</dependency>
dotnet add package Adobe.Target.Client
pip install target-python-sdk
3. SDK の初期化
ルールアーティファクトは、SDK の初期化手順の間にダウンロードされます。 初期化手順をカスタマイズして、アーティファクトのダウンロードおよび使用方法を決定できます。
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.
}
ClientConfig config = ClientConfig.builder()
.client("testClient")
.organizationId("ABCDEF012345677890ABCDEF0@AdobeOrg")
.build();
TargetClient targetClient = TargetClient.create(config);
var targetClientConfig = new TargetClientConfig.Builder("testClient", "ABCDEF012345677890ABCDEF0@AdobeOrg")
.Build();
this.targetClient.Initialize(targetClientConfig);
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 アクティビティの機能フラグの設定
-
Target で、Activities ページに移動し、Create Activity/A/B test を選択します。
-
Create A/B Test Activity モーダルでは、デフォルトの web オプションを選択したままにし(1)、experience composer として Form を選択し(2)、No Property Restrictions を使用して Default Workspace を選択し(3)、Next をクリックします(4)。
-
アクティビティ作成の Experiences の手順で、アクティビティの名前を指定し(1)、Add Experience をクリックして 2 つ目のエクスペリエンス Experience B を追加します(2)。 任意の場所の名前(3)を入力します。 例えば、
ondevice-featureflag
やhomepage-addtocart-featureflag
は、機能フラグテストの宛先を示す場所名です。 次の例では、エクスペリエンス B に対して定義された場所がondevice-featureflag
です。オプションで、オーディエンスの絞り込み(4)を追加して、アクティビティの選定を制限できます。 -
同じページの「CONTENT」セクションで、次に示すように、ドロップダウンの「Create JSON Offer (1)」を選択します。
-
表示される JSON Data テキストボックスに、有効な JSON オブジェクト(2)を使用して、各エクスペリエンス(1)の機能フラグ変数を入力します。
エクスペリエンス A の機能フラグ変数を入力します。
(上記のエクスペリエンス A のサンプル JSON)
{ "enabled" : true, "flag" : "expA" }
エクスペリエンス B の機能フラグ変数を入力します。
(前述のエクスペリエンス B のサンプル JSON)
{ "enabled" : true, "flag" : "expB" }
-
Next (1)をクリックして、アクティビティ作成の Targeting のステップに進みます。
-
以下に示す Targeting の手順の例では、簡単にするために、オーディエンスのターゲット設定(2)はすべての訪問者のデフォルトセットに残ります。 つまり、アクティビティはターゲット設定されていません。 ただし、Adobeでは、実稼動アクティビティのオーディエンスを常にターゲットにすることをお勧めします。 Next (3)をクリックして、アクティビティ作成の Goals & Settings のステップに進みます。
-
Goals & Settings の手順では、Reporting Source を Adobe Target (1)に設定します。 Conversion のように Goal Metric を定義し、サイトのコンバージョン指標(2)に基づいて詳細を指定します。 Save & Close (3)をクリックして、アクティビティを保存します。
5. アプリケーションで機能を実装し、レンダリングする
Target で機能フラグ変数を設定したら、それらを使用するようにアプリケーションコードを変更します。 例えば、アプリケーションで機能フラグを取得した後、それを使用して機能を有効にし、訪問者が認定したエクスペリエンスをレンダリングできます。
//... 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");
}
});
}
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");
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");
# ... 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 ()関数を使用してコンバージョンを追跡するための追加のイベントを送信できます。
//... 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"]
}
}
]
}
})
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);
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);
# ... 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 アクティビティをアクティブ化する
-
Activate (1)をクリックして、A/B Test アクティビティをアクティブ化します。
NOTE
この手順を実行するには、Approver または Publisher ユーザーの役割を持っている必要があります。