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:
Install the SDK and deploy code that sends events to Adobe Target.
Create and activate an Adobe Target activity with a goal metric in the UI.
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 Goal | Event |
---|---|
Conversion | Viewed a page, Viewed an mbox, and Clicked on mbox |
Revenue | Viewed an mbox and Clicked on mbox |
Engagement | Page 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()
When a prefetch object is passed within the request, the impression is not automatically incremented for the activities with mboxes within the prefetch object.
The sendNotifications
method can be used to manually send events to Adobe Target and trigger an impression.
Node.js#
Copied to your clipboardTargetClient.sendNotifications(options: Object): Promise
Java#
Copied to your clipboardResponseStatus 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 clipboard1const TargetClient = require("@adobe/target-nodejs-sdk");2const { v4: uuidv4 } = require("uuid");34const client = TargetClient.create({5 client: "acmeclient",6 organizationId: "1234567890@AdobeOrg",7 events: { clientReady: onTargetReady },8});910async function onTargetReady() {11 const targetResult = await client.getOffers({12 request: {13 targetRequest,14 prefetch: {15 mboxes: [16 {17 name: "homepage",18 index: 119 }20 ]21 },22 sessionId: uuidv4()23 }24 });2526 const { mboxes = [] } = targetResult.response.prefetch;2728 const request = {29 context: { channel: "web" },30 notifications: mboxes.map(mbox => {31 const { options = [] } = mbox;3233 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.name43 },44 tokens: options.map(option => option.eventToken)45 };46 })47 };48 // send the notification event49 await client.sendNotifications({ request });50}
Java#
Copied to your clipboard1ClientConfig clientConfig = ClientConfig.builder()2 .client("acmeclient")3 .organizationId("1234567890@AdobeOrg")4 .build();56TargetClient targetClient = TargetClient.create(clientConfig);78Context context = new Context()9 .channel(ChannelType.WEB)10 .address(new Address().url("http://www.target-demo-site.com"));1112TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()13 .context(context14 )15 .prefetch(new PrefetchRequest()16 .mboxes(new ArrayList() {{17 add(new MboxRequest().name("homepage").index(1));18 }})19 )20 .build());2122List<Notification> notifications = new ArrayList<>();23List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();2425for (PrefetchMboxResponse mbox : mboxes) {26 List<Option> options = mbox.getOptions();2728 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}3839TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()40 .context(context)41 .notifications(notifications).build();4243targetJavaClient.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 clipboard1const TargetClient = require("@adobe/target-nodejs-sdk");2const { v4: uuidv4 } = require("uuid");34const client = TargetClient.create({5 client: "acmeclient",6 organizationId: "1234567890@AdobeOrg",7 events: { clientReady: onTargetReady },8});910async function onTargetReady() {11 const targetResult = await client.getOffers({12 request: {13 targetRequest,14 prefetch: {15 mboxes: [16 {17 name: "homepage",18 index: 119 }20 ]21 },22 sessionId: uuidv4()23 }24 });2526 const { mboxes = [] } = targetResult.response.prefetch;2728 const request = {29 context: { channel: "web" },30 notifications: mboxes.map(mbox => {31 const { options = [], metrics = [] } = mbox;3233 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.name43 },44 tokens: metrics45 .filter(metric => metric.type === "click")46 .map(metric => metric.eventToken)47 };48 })49 };50 // send the notification event51 await client.sendNotifications({ request });52}
Java#
Copied to your clipboard1ClientConfig clientConfig = ClientConfig.builder()2 .client("acmeclient")3 .organizationId("1234567890@AdobeOrg")4 .build();56TargetClient targetClient = TargetClient.create(clientConfig);78Context context = new Context()9 .channel(ChannelType.WEB)10 .address(new Address().url("http://www.target-demo-site.com"));1112TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()13 .context(context14 )15 .prefetch(new PrefetchRequest()16 .mboxes(new ArrayList() {{17 add(new MboxRequest().name("homepage").index(1));18 }})19 )20 .build());2122List<Notification> notifications = new ArrayList<>();23List<PrefetchMboxResponse> mboxes = targetResult.getResponse().getPrefetch().getMboxes();2425for (PrefetchMboxResponse mbox : mboxes) {26 List<Metric> metrics = mbox.getMetrics();2728 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}4142TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()43 .context(context)44 .notifications(notifications).build();4546targetJavaClient.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 clipboard1const TargetClient = require("@adobe/target-nodejs-sdk");2const { v4: uuidv4 } = require("uuid");34const client = TargetClient.create({5 client: "acmeclient",6 organizationId: "1234567890@AdobeOrg",7 events: { clientReady: onTargetReady },8});910async function onTargetReady() {11 const targetResult = await client.getOffers({12 request: {13 targetRequest,14 prefetch: {15 views: [{}]16 },17 sessionId: uuidv4()18 }19 });2021 const { views = [] } = targetResult.response.prefetch;2223 const request = {24 context: { channel: "web" },25 notifications: views.map(view => {26 const { options = [], metrics = [] } = view;2728 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.name38 },39 tokens: options.map(option => option.eventToken)40 };41 })42 };43 // send the notification event44 await client.sendNotifications({ request });45}
Java#
Copied to your clipboard1ClientConfig clientConfig = ClientConfig.builder()2 .client("acmeclient")3 .organizationId("1234567890@AdobeOrg")4 .build();56TargetClient targetClient = TargetClient.create(clientConfig);78Context context = new Context()9 .channel(ChannelType.WEB)10 .address(new Address().url("http://www.target-demo-site.com"));1112TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()13 .context(context)14 .prefetch(new PrefetchRequest()15 .views(new ArrayList() {{16 add(new ViewRequest());17 }})18 )19 .build());2021List<Notification> notifications = new ArrayList<>();22List<View> views = targetResult.getResponse().getPrefetch().getViews();2324for (View view : views) {25 List<Option> options = view.getOptions();26 List<Metric> metrics = view.getMetrics();2728 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}3839TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()40 .context(context)41 .notifications(notifications).build();4243targetJavaClient.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 clipboard1const TargetClient = require("@adobe/target-nodejs-sdk");2const { v4: uuidv4 } = require("uuid");34const client = TargetClient.create({5 client: "acmeclient",6 organizationId: "1234567890@AdobeOrg",7 events: { clientReady: onTargetReady },8});910async function onTargetReady() {11 const targetResult = await client.getOffers({12 request: {13 targetRequest,14 prefetch: {15 views: [{}]16 },17 sessionId: uuidv4()18 }19 });2021 const { views = [] } = targetResult.response.prefetch;2223 const request = {24 context: { channel: "web" },25 notifications: views.map(view => {26 const { options = [], metrics = [] } = view;2728 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.name38 },39 tokens: metrics40 .filter(metric => metric.type === "click")41 .map(metric => metric.eventToken)42 };43 })44 };45 // send the notification event46 await client.sendNotifications({ request });47}
Java#
Copied to your clipboard1ClientConfig clientConfig = ClientConfig.builder()2 .client("acmeclient")3 .organizationId("1234567890@AdobeOrg")4 .build();56TargetClient targetClient = TargetClient.create(clientConfig);78Context context = new Context()9 .channel(ChannelType.WEB)10 .address(new Address().url("http://www.target-demo-site.com"));1112TargetDeliveryResponse targetResult = targetJavaClient.getOffers(TargetDeliveryRequest.builder()13 .context(context)14 .prefetch(new PrefetchRequest()15 .views(new ArrayList() {{16 add(new ViewRequest());17 }})18 )19 .build());2021List<Notification> notifications = new ArrayList<>();22List<View> views = targetResult.getResponse().getPrefetch().getViews();2324for (View view : views) {25 List<Option> options = view.getOptions();26 List<Metric> metrics = view.getMetrics();2728 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}4142TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder()43 .context(context)44 .notifications(notifications).build();4546targetJavaClient.sendNotifications(notificationRequest);