Edit in GitHubLog an issue

adobe.target.applyOffers(options) - at.js 2.x

This function lets you apply more than one offer that was retrieved by adobe.target.getOffers().

KeyTypeRequired?Description
selectorStringNoHTML element or CSS selector used to identify the HTML element where Target should place the offer content. If a selector is not provided, Target assumes that the HTML element to use is HTML HEAD.
ResponseObjectYesResponse object from getOffers().
See Requests table below.

Response#

Field NameDescription
response > prefetch > views > options > contentNote that the content of the "option" is not well-defined and depends directly on the option type/template structure.
response > prefetch > views > options > typeOption type. Reflects type of "content" field. Supported type is actions.
response > prefetch > views > stateAn opaque view state token that should be forwarded with display notification for the view
response > prefetch > views > options > responseTokensContains the map of responseTokens that have been collected when the current option was being processed.
response > prefetch > views > analytics > payloadAnalytics payload for client-side integration that should be sent to Analytics after the view has been applied.
response > prefetch > views > traceThe object containing all trace data for the prefetch call per view.
The trace object will also include a version for the trace.
The trace object will also include details of the current view.
response > prefetch > views > options > eventTokenEvent logging is done per option. For every applied option the respective event token should to be added to the list of notification tokens. Note that a View is composed of multiple options. If all options have been applied and seen, all eventTokens need to be included in the notification.
response > prefetch > views > nameThe human-readable view name.
response > prefetch > views > metricsReporting metrics that should be watched and then notify Target about. Currently, just click metric is supported. In case a click on the element happens, the appropriate eventTokens should be collected and a notification should be sent.
response > prefetch > views > keyThe key or fingerprint that identifies the view.
response > prefetch > views > idID of the view.
response > notifications > idNotification ID.
response > notifications > events > typeThe type of the notification, click, or display.
response > notifications > events > traceThe trace for the notification event.
response > notifications > events > tokenThe token that was sent with the notification event.
response > notifications > events > timestampThe timestamp that was sent with the notification event.
response > notifications > events > errorCodeIf the notification failed, the code indicates the reason for the failure.
response > notifications > eventsThe events that were logged or failed to be logged for the current notification.
response > notificationsIndicates the logged or failed notifications.
response > execute > mboxes > mbox > traceThe object containing all trace data for the individual mbox request.
response > execute > mboxes > mbox > responseTokensContains map of responseTokens for specific mbox request execution.
response > execute > mboxes > mbox > option > contentNote that the content of the "option" is not well-defined and depends directly on the option type/template structure.
response > execute > mboxes > mbox > option > typeOption type. Reflects type of "content" field. Supported types are: html, redirect, JSON, and dynamic.
response > execute > mboxes > mbox > optionsResponse option.
response > execute > mboxes > mbox > metrics > eventTokenToken of click event.
response > execute > mboxes > mbox > metrics > type"click"
response > execute > mboxes > mbox > metricsContains list of clickThrough metrics.
response > execute > mboxes > mbox > mboxThe name of the mbox.
response > execute > mboxes > mbox >indexIndicates that the response is for mbox with this index from the request.
response > execute > mboxes > mbox > analytics > payloadAnalytics payload for client-side integration that should be sent to Analytics after the mbox has been applied. (See A4T-enabled Campaigns section.)
response > execute > mboxesList of executed mboxes.
response > execute > pageLoad > options > contentNote that the content of the "option" is not well-defined and depends directly on the option type/template structure.
response > execute > pageLoad > options > typeOption type. Reflects type of "content" field. Supported types are: html, redirect, JSON, dynamic, and actions.
response > execute > pageLoad > optionsOptions that aren't grouped by views (target-global-mbox + options from activities with views not grouped by views).
response > execute > pageLoad > metricsClick metrics that were not set to belong to a specific view.
response > execute > pageLoad > traceThe object containing all trace data for the pageLoad request.
response > execute > pageLoad > analytics > payloadAnalytics payload for client-side integration that should be sent to Analytics after the page load content has been applied. (See A4T-enabled Campaigns section.)

Example applyOffers() call#

Copied to your clipboard
1adobe.target.applyOffers({response:{
2 "execute": {
3 "pageLoad": {
4 "options": [{
5 "type": "html",
6 "content": "page-load"
7 },
8 {
9 "type": "actions",
10 "content": [{
11 "type": "setHtml",
12 "content": "<h1>Container 1</h1>",
13 "selector": "#container1",
14 "cssSelector": "#container1"
15 },
16 {
17 "type": "setHtml",
18 "content": "<h3>Container 3</h3>",
19 "selector": "#container3",
20 "cssSelector": "#container3"
21 }]
22 }],
23
24
25 "metrics": [{
26 "type": "click",
27 "selector": "#container1",
28 "eventToken": "page-load-click-metric"
29 }]
30 }
31 }
32}});

Example calls of Promise chaining with getOffers() and applyOffers(), because these functions are Promise based#

Copied to your clipboard
1adobe.target.getOffers({...})
2.then(response => adobe.target.applyOffers({ response: response }))
3.then(() => console.log("Success"))
4.catch(error => console.log("Error", error));

For more examples on how to use getOffers(), please refer to the getOffers documentation

Page Load Request Example#

Copied to your clipboard
1adobe.target.getOffers({
2 request: {
3 execute: {
4 pageLoad: {}
5 }
6 }
7}).
8then(response => adobe.target.applyOffers({ response: response }))
9.then(() => console.log("Success"))
10.catch(error => console.log("Error", error));
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.