Edit in GitHubLog an issue

Event tracking

Use Adobe Target's event tracking capabilities to effectively measure metrics that matter most for your business and use cases. Tracking events is key to measuring the success of your experimentation or personalization activities, since they tell you which variation or experience is winning or losing. Understanding this will help you understand how your users are engaging with your product or evolving in an ever-changing landscape.

In order to track events through Adobe Target's SDKs, follow this 2-step process:

  1. Install the SDK and deploy code that sends events to Adobe Target.

  2. Create and activate an Adobe Target activity with a goal metric in the UI.

    alt image

Goal Metrics and Events#

The following table defines the combination of goals and events you can define and measure with a Target Activity using Target's reporting capabilities:

Primary GoalEvent
ConversionViewed a page, Viewed an mbox, and Clicked on mbox
RevenueViewed an mbox and Clicked on mbox
EngagementPage Views, Customer Scoring, and Time on Site

How impressions are triggered#

Target SDKs call the underlying Delivery API. When an execute object with required parameters is within the request itself, the impression is incremented automatically for qualifying activities. SDK methods that increment an impression automatically are:

  • getOffers()
  • getAttributes()

The sendNotifications method can be used to manually send events to Adobe Target and trigger an impression.

Node.js#

Copied to your clipboard
TargetClient.sendNotifications(options: Object): Promise

Java#

Copied to your clipboard
ResponseStatus TargetClient.sendNotifications(TargetDeliveryRequest request)

Sample Code#

The following code samples work for all goal metric types whether it be Conversion, Revenue or Engagement.

Viewed a Page or Mbox#

This sample first gets a target mbox offer using getOffers. It then constructs a request with a notification based on that mbox offer.

The notification type property is set to display.

To indicate a page was viewed, it is important to specify the the address object in the notification payload. Be sure to set the URL accordingly.

For mboxes, you must set the mbox property on the notification object and provide an array of tokens based on the options array in the targetResult.

Node.js#

Copied to your clipboard
1const TargetClient = require("@adobe/target-nodejs-sdk");
2const { v4: uuidv4 } = require("uuid");
3
4const client = TargetClient.create({
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg",
7 events: { clientReady: onTargetReady },
8});
9
10async function onTargetReady() {
11 const targetResult = await client.getOffers({
12 request: {
13 targetRequest,
14 prefetch: {
15 mboxes: [
16 {
17 name: "homepage",
18 index: 1
19 }
20 ]
21 },
22 sessionId: uuidv4()
23 }
24 });
25
26 const { mboxes = [] } = targetResult.response.prefetch;
27
28 const request = {
29 context: { channel: "web" },
30 notifications: mboxes.map(mbox => {
31 const { options = [] } = mbox;
32
33 return {
34 id: targetResult.response.id,
35 impressionId: uuidv4(),
36 address: {
37 url: "http://www.target-demo-site.com"
38 },
39 timestamp: new Date().getTime(),
40 type: "display",
41 mbox: {
42 name: mbox.name
43 },
44 tokens: options.map(option => option.eventToken)
45 };
46 })
47 };
48 // send the notification event
49 await client.sendNotifications({ request });
50}

Java#

Copied to your clipboard
1ClientConfig clientConfig = ClientConfig.builder()
2 .client("acmeclient")
3 .organizationId("1234567890@AdobeOrg")
4 .build();
5
6TargetClient targetClient = TargetClient.create(clientConfig);
7
8Context context = new Context()
9 .channel(ChannelType.WEB)
10 .address(new Address().url("http://www.target-demo-site.com"));
11
12TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
13 .context(context
14 )
15 .prefetch(new PrefetchRequest()
16 .mboxes(new ArrayList() {{
17 add(new MboxRequest().name("homepage").index(1));
18 }})
19 )
20 .build());
21
22List<Notification> notifications = new ArrayList<>();
23List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();
24
25for (PrefetchMboxResponse mbox : mboxes) {
26 List<Option> options = mbox.getOptions();
27
28 notifications.add((Notification) new Notification()
29 .id(targetResult.getResponse().getRequestId())
30 .impressionId(UUID.randomUUID().toString())
31 .timestamp(System.currentTimeMillis())
32 .type(MetricType.DISPLAY)
33 .mbox(new NotificationMbox().name(mbox.getName()))
34 .tokens(options.stream().map(Option::getEventToken).collect(Collectors.toList()))
35 .address(new Address().url("http://www.target-demo-site.com"))
36 );
37}
38
39TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
40 .context(context)
41 .notifications(notifications).build();
42
43targetJavaClient.sendNotifications(notificationRequest);

Clicked an Mbox#

This sample first gets a target mbox offer using getOffers. It then constructs a request with a notification based on that mbox offer.

The notification type property is set to click.

You must set the mbox property on the notification object and provide an array of tokens based on the metrics array in the targetResult.

Node.js#

Copied to your clipboard
1const TargetClient = require("@adobe/target-nodejs-sdk");
2const { v4: uuidv4 } = require("uuid");
3
4const client = TargetClient.create({
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg",
7 events: { clientReady: onTargetReady },
8});
9
10async function onTargetReady() {
11 const targetResult = await client.getOffers({
12 request: {
13 targetRequest,
14 prefetch: {
15 mboxes: [
16 {
17 name: "homepage",
18 index: 1
19 }
20 ]
21 },
22 sessionId: uuidv4()
23 }
24 });
25
26 const { mboxes = [] } = targetResult.response.prefetch;
27
28 const request = {
29 context: { channel: "web" },
30 notifications: mboxes.map(mbox => {
31 const { options = [], metrics = [] } = mbox;
32
33 return {
34 id: targetResult.response.id,
35 impressionId: uuidv4(),
36 address: {
37 url: "http://www.target-demo-site.com"
38 },
39 timestamp: new Date().getTime(),
40 type: "click",
41 mbox: {
42 name: mbox.name
43 },
44 tokens: metrics
45 .filter(metric => metric.type === "click")
46 .map(metric => metric.eventToken)
47 };
48 })
49 };
50 // send the notification event
51 await client.sendNotifications({ request });
52}

Java#

Copied to your clipboard
1ClientConfig clientConfig = ClientConfig.builder()
2 .client("acmeclient")
3 .organizationId("1234567890@AdobeOrg")
4 .build();
5
6TargetClient targetClient = TargetClient.create(clientConfig);
7
8Context context = new Context()
9 .channel(ChannelType.WEB)
10 .address(new Address().url("http://www.target-demo-site.com"));
11
12TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
13 .context(context
14 )
15 .prefetch(new PrefetchRequest()
16 .mboxes(new ArrayList() {{
17 add(new MboxRequest().name("homepage").index(1));
18 }})
19 )
20 .build());
21
22List<Notification> notifications = new ArrayList<>();
23List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();
24
25for (PrefetchMboxResponse mbox : mboxes) {
26 List<Metric> metrics = mbox.getMetrics();
27
28 notifications.add((Notification) new Notification()
29 .id(targetResult.getResponse().getRequestId())
30 .impressionId(UUID.randomUUID().toString())
31 .timestamp(System.currentTimeMillis())
32 .type(MetricType.CLICK)
33 .mbox(new NotificationMbox().name(mbox.getName()))
34 .tokens(metrics.stream()
35 .filter(metric -> MetricType.CLICK.equals(metric.getType()))
36 .map(Metric::getEventToken)
37 .collect(Collectors.toList()))
38 .address(new Address().url("http://www.target-demo-site.com"))
39 );
40}
41
42TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
43 .context(context)
44 .notifications(notifications).build();
45
46targetJavaClient.sendNotifications(notificationRequest);

Viewed a View#

This sample first gets target views using getOffers. It then constructs a request with a notification based on those views.

The notification type property is set to display.

For views, you must set the view property on the notification object and provide an array of tokens based on the options array in the targetResult.

Node.js#

Copied to your clipboard
1const TargetClient = require("@adobe/target-nodejs-sdk");
2const { v4: uuidv4 } = require("uuid");
3
4const client = TargetClient.create({
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg",
7 events: { clientReady: onTargetReady },
8});
9
10async function onTargetReady() {
11 const targetResult = await client.getOffers({
12 request: {
13 targetRequest,
14 prefetch: {
15 views: [{}]
16 },
17 sessionId: uuidv4()
18 }
19 });
20
21 const { views = [] } = targetResult.response.prefetch;
22
23 const request = {
24 context: { channel: "web" },
25 notifications: views.map(view => {
26 const { options = [], metrics = [] } = view;
27
28 return {
29 id: targetResult.response.id,
30 impressionId: uuidv4(),
31 address: {
32 url: "http://www.target-demo-site.com"
33 },
34 timestamp: new Date().getTime(),
35 type: "display",
36 view: {
37 name: view.name
38 },
39 tokens: options.map(option => option.eventToken)
40 };
41 })
42 };
43 // send the notification event
44 await client.sendNotifications({ request });
45}

Java#

Copied to your clipboard
1ClientConfig clientConfig = ClientConfig.builder()
2 .client("acmeclient")
3 .organizationId("1234567890@AdobeOrg")
4 .build();
5
6TargetClient targetClient = TargetClient.create(clientConfig);
7
8Context context = new Context()
9 .channel(ChannelType.WEB)
10 .address(new Address().url("http://www.target-demo-site.com"));
11
12TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
13 .context(context)
14 .prefetch(new PrefetchRequest()
15 .views(new ArrayList() {{
16 add(new ViewRequest());
17 }})
18 )
19 .build());
20
21List<Notification> notifications = new ArrayList<>();
22List<View> views = targetResult.getResponse().getPrefetch().getViews();
23
24for (View view : views) {
25 List<Option> options = view.getOptions();
26 List<Metric> metrics = view.getMetrics();
27
28 notifications.add((Notification) new Notification()
29 .id(targetResult.getResponse().getRequestId())
30 .impressionId(UUID.randomUUID().toString())
31 .timestamp(System.currentTimeMillis())
32 .type(MetricType.DISPLAY)
33 .view(new NotificationView().name(view.getName()))
34 .tokens(options.stream().map(Option::getEventToken).collect(Collectors.toList()))
35 .address(new Address().url("http://www.target-demo-site.com"))
36 );
37}
38
39TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
40 .context(context)
41 .notifications(notifications).build();
42
43targetJavaClient.sendNotifications(notificationRequest);

Clicked a View#

This sample first gets target views using getOffers. It then constructs a request with notifications based on those views.

The notification type property is set to click.

You must set the view property on the notification object and provide an array of tokens based on the metrics array in the targetResult.

Node.js#

Copied to your clipboard
1const TargetClient = require("@adobe/target-nodejs-sdk");
2const { v4: uuidv4 } = require("uuid");
3
4const client = TargetClient.create({
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg",
7 events: { clientReady: onTargetReady },
8});
9
10async function onTargetReady() {
11 const targetResult = await client.getOffers({
12 request: {
13 targetRequest,
14 prefetch: {
15 views: [{}]
16 },
17 sessionId: uuidv4()
18 }
19 });
20
21 const { views = [] } = targetResult.response.prefetch;
22
23 const request = {
24 context: { channel: "web" },
25 notifications: views.map(view => {
26 const { options = [], metrics = [] } = view;
27
28 return {
29 id: targetResult.response.id,
30 impressionId: uuidv4(),
31 address: {
32 url: "http://www.target-demo-site.com"
33 },
34 timestamp: new Date().getTime(),
35 type: "click",
36 view: {
37 name: view.name
38 },
39 tokens: metrics
40 .filter(metric => metric.type === "click")
41 .map(metric => metric.eventToken)
42 };
43 })
44 };
45 // send the notification event
46 await client.sendNotifications({ request });
47}

Java#

Copied to your clipboard
1ClientConfig clientConfig = ClientConfig.builder()
2 .client("acmeclient")
3 .organizationId("1234567890@AdobeOrg")
4 .build();
5
6TargetClient targetClient = TargetClient.create(clientConfig);
7
8Context context = new Context()
9 .channel(ChannelType.WEB)
10 .address(new Address().url("http://www.target-demo-site.com"));
11
12TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()
13 .context(context)
14 .prefetch(new PrefetchRequest()
15 .views(new ArrayList() {{
16 add(new ViewRequest());
17 }})
18 )
19 .build());
20
21List<Notification> notifications = new ArrayList<>();
22List<View> views = targetResult.getResponse().getPrefetch().getViews();
23
24for (View view : views) {
25 List<Option> options = view.getOptions();
26 List<Metric> metrics = view.getMetrics();
27
28 notifications.add((Notification) new Notification()
29 .id(targetResult.getResponse().getRequestId())
30 .impressionId(UUID.randomUUID().toString())
31 .timestamp(System.currentTimeMillis())
32 .type(MetricType.CLICK)
33 .view(new NotificationView().name(view.getName()))
34 .tokens(metrics.stream()
35 .filter(metric -> MetricType.CLICK.equals(metric.getType()))
36 .map(Metric::getEventToken)
37 .collect(Collectors.toList()))
38 .address(new Address().url("http://www.target-demo-site.com"))
39 );
40}
41
42TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()
43 .context(context)
44 .notifications(notifications).build();
45
46targetJavaClient.sendNotifications(notificationRequest);
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.