事件追蹤
建立對象:
- undefined
使用Adobe Target的事件追蹤功能,有效測量對您的業務與使用案例而言最重要的量度。 追蹤事件是衡量實驗或個人化活動是否成功的關鍵,因為它們可告訴您哪些變數或體驗是成功或失敗。 瞭解此資訊有助於您瞭解使用者如何與您的產品互動,或在不斷變化的環境中發展。
若要透過Adobe Target的SDK追蹤事件,請遵循此兩步驟程式:
-
安裝SDK並部署會將事件傳送至Adobe Target的程式碼。
-
在UI中建立並啟用具有目標量度的Adobe Target活動。
目標量度和事件
下表定義了目標與事件的組合,您可以使用Target的報告功能,透過Target活動來定義與測量:
閱聽的觸發方式
Target SDK會呼叫基礎傳送API。 當具有必要引數的執行物件位於請求本身中時,曝光會自動遞增以用於合格活動。 自動增加曝光次數的SDK方法為:
- getOffers()
- getAttributes()
sendNotifications
方法可用來手動將事件傳送至Adobe Target並觸發曝光。
TargetClient.sendNotifications(options: Object): Promise
ResponseStatus TargetClient.sendNotifications(TargetDeliveryRequest request)
程式碼範例
以下程式碼範例適用於所有目標量度型別,不論是「轉換」、「收入」或「參與」。
已檢視頁面或Mbox
此範例先使用getOffers
取得Target mbox選件。 接著,系統會根據該mbox選件,以通知來建構要求。
通知type
屬性設定為display
。
若要指出已檢視頁面,在通知裝載中指定位址物件非常重要。 請務必適當地設定URL。
針對mbox,您必須在通知物件上設定mbox屬性,並根據targetResult
中的選項陣列提供代號陣列。
const TargetClient = require("@adobe/target-nodejs-sdk");
const { v4: uuidv4 } = require("uuid");
const client = TargetClient.create({
client: "acmeclient",
organizationId: "1234567890@AdobeOrg",
events: { clientReady: onTargetReady },
});
async function onTargetReady() {
const targetResult = await client.getOffers({
request: {
targetRequest,
prefetch: {
mboxes: [
{
name: "homepage",
index: 1
}
]
},
sessionId: uuidv4()
}
});
const { mboxes = [] } = targetResult.response.prefetch;
const request = {
context: { channel: "web" },
notifications: mboxes.map(mbox => {
const { options = [] } = mbox;
return {
id: targetResult.response.id,
impressionId: uuidv4(),
address: {
url: "http://www.target-demo-site.com"
},
timestamp: new Date().getTime(),
type: "display",
mbox: {
name: mbox.name
},
tokens: options.map(option => option.eventToken)
};
})
};
// send the notification event
await client.sendNotifications({ request });
}
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
Context context = new Context()
.channel(ChannelType.WEB)
.address(new Address().url("http://www.target-demo-site.com"));
TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
.context(context
)
.prefetch(new PrefetchRequest()
.mboxes(new ArrayList() {{
add(new MboxRequest().name("homepage").index(1));
}})
)
.build());
List<Notification> notifications = new ArrayList<>();
List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();
for (PrefetchMboxResponse mbox : mboxes) {
List<Option> options = mbox.getOptions();
notifications.add((Notification) new Notification()
.id(targetResult.getResponse().getRequestId())
.impressionId(UUID.randomUUID().toString())
.timestamp(System.currentTimeMillis())
.type(MetricType.DISPLAY)
.mbox(new NotificationMbox().name(mbox.getName()))
.tokens(options.stream().map(Option::getEventToken).collect(Collectors.toList()))
.address(new Address().url("http://www.target-demo-site.com"))
);
}
TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
.context(context)
.notifications(notifications).build();
targetJavaClient.sendNotifications(notificationRequest);
已按一下Mbox
此範例先使用getOffers
取得Target mbox選件。 接著,系統會根據該mbox選件,以通知來建構要求。
通知type
屬性設定為click
。
您必須在通知物件上設定mbox
屬性,並根據targetResult
中的量度陣列提供權杖陣列。
const TargetClient = require("@adobe/target-nodejs-sdk");
const { v4: uuidv4 } = require("uuid");
const client = TargetClient.create({
client: "acmeclient",
organizationId: "1234567890@AdobeOrg",
events: { clientReady: onTargetReady },
});
async function onTargetReady() {
const targetResult = await client.getOffers({
request: {
targetRequest,
prefetch: {
mboxes: [
{
name: "homepage",
index: 1
}
]
},
sessionId: uuidv4()
}
});
const { mboxes = [] } = targetResult.response.prefetch;
const request = {
context: { channel: "web" },
notifications: mboxes.map(mbox => {
const { options = [], metrics = [] } = mbox;
return {
id: targetResult.response.id,
impressionId: uuidv4(),
address: {
url: "http://www.target-demo-site.com"
},
timestamp: new Date().getTime(),
type: "click",
mbox: {
name: mbox.name
},
tokens: metrics
.filter(metric => metric.type === "click")
.map(metric => metric.eventToken)
};
})
};
// send the notification event
await client.sendNotifications({ request });
}
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
Context context = new Context()
.channel(ChannelType.WEB)
.address(new Address().url("http://www.target-demo-site.com"));
TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
.context(context
)
.prefetch(new PrefetchRequest()
.mboxes(new ArrayList() {{
add(new MboxRequest().name("homepage").index(1));
}})
)
.build());
List<Notification> notifications = new ArrayList<>();
List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();
for (PrefetchMboxResponse mbox : mboxes) {
List<Metric> metrics = mbox.getMetrics();
notifications.add((Notification) new Notification()
.id(targetResult.getResponse().getRequestId())
.impressionId(UUID.randomUUID().toString())
.timestamp(System.currentTimeMillis())
.type(MetricType.CLICK)
.mbox(new NotificationMbox().name(mbox.getName()))
.tokens(metrics.stream()
.filter(metric -> MetricType.CLICK.equals(metric.getType()))
.map(Metric::getEventToken)
.collect(Collectors.toList()))
.address(new Address().url("http://www.target-demo-site.com"))
);
}
TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
.context(context)
.notifications(notifications).build();
targetJavaClient.sendNotifications(notificationRequest);
已檢視的檢視
此範例先使用getOffers
取得目標檢視。 然後它會根據這些檢視建構包含通知的請求。
通知type
屬性設定為display
。
針對檢視,您必須在通知物件上設定view
屬性,並根據targetResult中的選項陣列提供一組代號。
const TargetClient = require("@adobe/target-nodejs-sdk");
const { v4: uuidv4 } = require("uuid");
const client = TargetClient.create({
client: "acmeclient",
organizationId: "1234567890@AdobeOrg",
events: { clientReady: onTargetReady },
});
async function onTargetReady() {
const targetResult = await client.getOffers({
request: {
targetRequest,
prefetch: {
views: [{}]
},
sessionId: uuidv4()
}
});
const { views = [] } = targetResult.response.prefetch;
const request = {
context: { channel: "web" },
notifications: views.map(view => {
const { options = [], metrics = [] } = view;
return {
id: targetResult.response.id,
impressionId: uuidv4(),
address: {
url: "http://www.target-demo-site.com"
},
timestamp: new Date().getTime(),
type: "display",
view: {
name: view.name
},
tokens: options.map(option => option.eventToken)
};
})
};
// send the notification event
await client.sendNotifications({ request });
}
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
Context context = new Context()
.channel(ChannelType.WEB)
.address(new Address().url("http://www.target-demo-site.com"));
TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
.context(context)
.prefetch(new PrefetchRequest()
.views(new ArrayList() {{
add(new ViewRequest());
}})
)
.build());
List<Notification> notifications = new ArrayList<>();
List<View> views = targetResult.getResponse().getPrefetch().getViews();
for (View view : views) {
List<Option> options = view.getOptions();
List<Metric> metrics = view.getMetrics();
notifications.add((Notification) new Notification()
.id(targetResult.getResponse().getRequestId())
.impressionId(UUID.randomUUID().toString())
.timestamp(System.currentTimeMillis())
.type(MetricType.DISPLAY)
.view(new NotificationView().name(view.getName()))
.tokens(options.stream().map(Option::getEventToken).collect(Collectors.toList()))
.address(new Address().url("http://www.target-demo-site.com"))
);
}
TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
.context(context)
.notifications(notifications).build();
targetJavaClient.sendNotifications(notificationRequest);
按一下檢視
此範例先使用getOffers
取得目標檢視。 然後它會根據這些檢視建構包含通知的請求。
通知type
屬性設定為click
。
您必須在通知物件上設定view
屬性,並根據targetResult中的量度陣列提供權杖陣列。
const TargetClient = require("@adobe/target-nodejs-sdk");
const { v4: uuidv4 } = require("uuid");
const client = TargetClient.create({
client: "acmeclient",
organizationId: "1234567890@AdobeOrg",
events: { clientReady: onTargetReady },
});
async function onTargetReady() {
const targetResult = await client.getOffers({
request: {
targetRequest,
prefetch: {
views: [{}]
},
sessionId: uuidv4()
}
});
const { views = [] } = targetResult.response.prefetch;
const request = {
context: { channel: "web" },
notifications: views.map(view => {
const { options = [], metrics = [] } = view;
return {
id: targetResult.response.id,
impressionId: uuidv4(),
address: {
url: "http://www.target-demo-site.com"
},
timestamp: new Date().getTime(),
type: "click",
view: {
name: view.name
},
tokens: metrics
.filter(metric => metric.type === "click")
.map(metric => metric.eventToken)
};
})
};
// send the notification event
await client.sendNotifications({ request });
}
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
Context context = new Context()
.channel(ChannelType.WEB)
.address(new Address().url("http://www.target-demo-site.com"));
TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
.context(context)
.prefetch(new PrefetchRequest()
.views(new ArrayList() {{
add(new ViewRequest());
}})
)
.build());
List<Notification> notifications = new ArrayList<>();
List<View> views = targetResult.getResponse().getPrefetch().getViews();
for (View view : views) {
List<Option> options = view.getOptions();
List<Metric> metrics = view.getMetrics();
notifications.add((Notification) new Notification()
.id(targetResult.getResponse().getRequestId())
.impressionId(UUID.randomUUID().toString())
.timestamp(System.currentTimeMillis())
.type(MetricType.CLICK)
.view(new NotificationView().name(view.getName()))
.tokens(metrics.stream()
.filter(metric -> MetricType.CLICK.equals(metric.getType()))
.map(Metric::getEventToken)
.collect(Collectors.toList()))
.address(new Address().url("http://www.target-demo-site.com"))
);
}
TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
.context(context)
.notifications(notifications).build();
targetJavaClient.sendNotifications(notificationRequest);