sendNotifications() call after rendering prefetched mboxes
function createTokens(options) {
return options.map(e => e.eventToken);
}
function createNotification(mbox, type, tokens) {
const id = 11111; // here we should use a random ID like UUID
const timestamp = Date.now();
const { name, state, parameters, profileParameters, order, product } = mbox;
const result = {
id,
type,
timestamp,
parameters,
profileParameters,
order,
product
};
result.mbox = { name, state };
result.tokens = tokens;
return result;
}
adobe.target.getOffers({
request: {
prefetch: {
mboxes: [
{
index: 0,
name: "a1-serverside-ab"
}
]
}
}
})
.then(response => {
const mboxes = response.prefetch.mboxes;
const notifications = mboxes.map(mbox => {
const type = "display";
const tokens = createTokens(mbox.options);
return createNotification(mbox, type, tokens);
});
adobe.target.sendNotifications({
request: { notifications }
});
})
If you are using Adobe Analytics,
getOffers()
with prefetch only and sendNotifications()
, the Analytics request must be fired after sendNotifications()
is executed. The purpose of this is to ensure that the SDID generated by sendNotifications()
matches the SDID sent to Analytics and Target.Previous pageregisterExtension() - at.js 1.x
Next pageat.js custom events