adobe.target.getOffers() - at.js 2.x
This function lets you retrieve multiple offers by passing in multiple mboxes. Additionally, multiple offers can be retrieved for all views in active activities.
consumerId
Default value is client’s global mbox if not provided. This key is used to generate the supplemental data ID (SDID) used for A4T integration.
When using getOffers()
, each call generates a new SDID. If you have multiple mbox requests on the same page, and want to preserve the SDID (so that it matches the SDID from the target-global-mbox and the Adobe Analytics SDID), use the consumerId
parameter.
If getOffers()
includes three mboxes (named “mbox1”, “mbox2”, and “mbox3”), include: consumerId: "mbox1, mbox2, mbox3"
in the getOffers()
call.
decisioningMethod
request
timeout
Request
tntId
, thirdPartyId
, or marketingCloudVisitorId
is required.The following must be implemented on page:
- Visitor ID Service
- Appmeasurement.js
The following values are supported:
client_side: When specified, an analytics payload will be returned to the caller which should be used to send to Adobe Analytics via the Data Insertion API.
server_side: This is the default value where the Target and Analytics backend will use the SDID to stitch the calls together for reporting purposes.
Maximum count 50.
Name not blank.
Name length <=
128.
Value length <=
5000.
Name should not start with “profile”.
Not allowed names: “orderId”, “orderTotal”, “productPurchasedId”.
Maximim count 50.
Name not blank.
Name length <=
128.
Value length <=
5000.
Accepts String values only.
Name should not start with “profile”.
Not blank.
maximum size = 128.
Not blank.
maximum size = 128.
>=
0.No blank values.
Each value’s max length 50.
Concatenated and separated by comma.
Product IDs total length <=
250.
Request > execute > pageLoad
parameters
Maximum count 50.
Name not blank.
Name length <=
128.
Value length <=
5000.
Accepts String values only.
Name should not start with “profile”.
Not allowed names: “orderId”, “orderTotal”, “productPurchasedId”.
Request > execute > pageLoad
profileParameters
Maximum count 50.
Name not blank.
Name length <=
128.
Value length <=
256.
Name should not start with “profile”.
Accepts String values only.
Request > execute > pageLoad
product
Request > execute > pageLoad
product -> id
Not blank.
Maximum size = 128.
Request > execute > pageLoad
product > categoryId
Not blank.
Maximum size = 128.
Request > execute > pageLoad
order
Request > execute > pageLoad
order > id
Request > execute > pageLoad
order > total
>=
0.Request > execute > pageLoad
order > purchasedProductIds
No blank values.
Each value’s max length 50.
Concatenated and separated by comma.
Product IDs total length <=
250.
Maximum size = 50.
No null elements.
Not blank.
No ‘-clicked’ suffix.
Maximum size = 250.
Allowed characters: `'-, ./=:;&!@#$%^&*()+
Not null.
Unique.
>=
0.
Maximum count = 50.
Name not blank.
Name length <=
128.
Accepts String values only.
Value length <=
5000.
Name should not start with “profile.”
Not allowed names: “orderId”, “orderTotal”, “productPurchasedId”.
Maximum count = 50.
Name not blank.
Name length <=
128.
Accepts String values only.
Value length <=
256.
Name should not start with “profile.”
Not blank.
Maximum size = 128.
Not blank.
Maximum size = 128.
>=
0.No blank values.
Each value’s maximum length = 50.
Concatenated and separated by comma.
Product ids total length <=
250.
Call getOffers() for all views
adobe.target.getOffers({
request: {
prefetch: {
views: [{}]
}
}
});
Call getOffers() to make an on-device decisioning
adobe.target.getOffers({
decisioningMethod:"on-device",
request: {
execute: {
mboxes: [
{
index: 0,
name: "homepage"
}
]
}
}
});
Call getOffers() to retrieve the latest views with the passed-in parameters and profile parameters
adobe.target.getOffers({
request: {
"prefetch": {
"views": [
{
"parameters": {
"ad": "1"
},
"profileParameters": {
"age": 23
}
}
]
}
}
});
Call getOffers() to retrieve mboxes with parameters and profile parameters passed-in.
adobe.target.getOffers({
request: {
execute: {
mboxes: [
{
index: 0,
name: "first-mbox"
},
{
index: 1,
name: "second-mbox",
parameters: {
a: 1
},
profileParameters: {
b: 2
}
}
]
}
}
});
Call getOffers() to retrieve the analytics payload from the client side
adobe.target.getOffers({
request: {
experienceCloud: {
analytics: {
logging: "client_side"
}
},
prefetch: {
mboxes: [{
index: 0,
name: "a1-serverside-xt"
}]
}
}
})
.then(console.log)
Response:
{
"prefetch": {
"mboxes": [{
"index": 0,
"name": "a1-serverside-xt",
"options": [{
"content": "<img src=\"http://s7d2.scene7.com/is/image/TargetAdobeTargetMobile/L4242-xt-usa?tm=1490025518668&fit=constrain&hei=491&wid=980&fmt=png-alpha\"/>",
"type": "html",
"eventToken": "n/K05qdH0MxsiyH4gX05/2qipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
"responseTokens": {
"profile.memberlevel": "0",
"geo.city": "bucharest",
"activity.id": "167169",
"experience.name": "USA Experience",
"geo.country": "romania"
}
}],
"analytics": {
"payload": {
"pe": "tnt",
"tnta": "167169:0:0|0|100,167169:0:0|2|100,167169:0:0|1|100"
}
}
}]
}
}
The payload can then be forwarded to Adobe Analytics via the Data Insertion API.
Fetch and render data from multiple mboxes via getOffers() and applyOffers()
at.js 2.x lets you fetch multiple mboxes via the getOffers()
API. You can also fetch data for multiple mboxes and then use applyOffers()
to render the data in different locations identified by a CSS selector.
The following example shows a simple HTML page with at.js 2.x implemented:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>at.js 2.x, multiple selectors and multiple mboxes</title>
<script src="at.js"></script>
</head>
<body>
<div id="container1">Default content 1</div>
<div id="container2">Default content 2</div>
<div id="container3">Default content 3</div>
</body>
</html>
Assume that you have three containers that you want to modify via content received from Target. You can construct a single request for three mboxes in which each mbox has some content to render into the respective container.
The request and rendering code might look like the following example:
adobe.target.getOffers({
request: {
prefetch: {
mboxes: [
{
index: 0,
name: "mbox1"
},
{
index: 1,
name: "mbox2"
},
{
index: 2,
name: "mbox3"
}
]
}
}
})
.then(response => {
// get all mboxes from response
const mboxes = response.prefetch.mboxes;
let count = 1;
mboxes.forEach(el => {
adobe.target.applyOffers({
selector: "#container" + count,
response: {
prefetch: {
mboxes: [el]
}
}
});
count += 1;
});
});
In the request > prefetch > mboxes
section, there are three different mboxes. If the request completed successfully, you receive the response for each mbox from response > prefetch > mboxes
. After you have the responses and the locations you want to use for rendering, you can invoke applyOffers()
to render the content retrieved from Target. In this example we have the following mapping:
- mbox1 > CSS selector #container1
- mbox2 > CSS selector #container2
- mbox3 > CSS selector #container3
This example uses the count variable to construct the CSS selectors. In a real-life scenario you could use a different mapping between the CSS selector and mbox.
Note that this example uses prefetch > mboxes
, but you could also use execute > mboxes
. Ensure that if you use prefetch in getOffers()
, you should also use prefetch in the applyOffers()
invocation.
Call getOffers() to perform a pageLoad
The following example shows you how to perform a pageLoad using getOffers() with at.js 2.x
adobe.target.getOffers({
request: {
execute: {
pageLoad: {
parameters: {}
}
}
}
});