Edit in GitHubLog an issue

adobe.target.getOffer(options)

This function fires a request to get a Target offer.

Use with adobe.target.applyOffer() to process the response or use your own success handling. The options parameter is mandatory and has the following structure:

KeyTypeRequiredDescription
mboxStringYesMbox name
paramsObjectNoMbox parameters. An object of key-value pairs that has the following structure:
{ "param1": "value1", "param2": "value2"}
successFunctionYesCallback to be executed when we got a response from the server. The success callback function will receive a single parameter that represents an array of offer objects. Here is a success callback example:
function handleSuccess(response){......}
See Responses below for details.
errorFunctionYesCallback to be executed when we got an error. There are a few cases that are considered erroneous:
  • HTTP status code different from 200 OK
  • Response can not be parsed. For example we poorly constructed JSON or HTML instead of JSON.
  • Response contains the "error" key. For example an exception was thrown on the edge a request could not be properly processed. We could get an error when an mbox is blocked and we could not retrieve any content for it, etc. The error callback function will receive two parameters: status and error. Here is an error callback example: function handleError(status, error){......}
See Error Responses below for details.
timeoutNumberNoTimeout in milliseconds. If not specified, the default timeout in at.js will be used.
The default timeout can be set from the Target UI under Administration > Implementation.

Examples#

Adding parameters with getOffer() and using applyOffer() for success-handling:

Copied to your clipboard
1adobe.target.getOffer({
2 "mbox": "target-global-mbox",
3 "params": {
4 "a": 1,
5 "b": 2
6 },
7 "success": function(offer) {
8 adobe.target.applyOffer( {
9 "mbox": "target-global-mbox",
10 "offer": offer
11 } );
12 },
13 "error": function(status, error) {
14 console.log('Error', status, error);
15 }
16});

Adding parameters and profile parameters with getOffer() and using applyOffer() for success-handling:

Copied to your clipboard
1adobe.target.getOffer({
2 "mbox": "target-global-mbox",
3 "params": {
4 "a": 1,
5 "b": 2,
6 "profile.age": 27,
7 "profile.gender": "male"
8 },
9 "success": function(offer) {
10 adobe.target.applyOffer( {
11 "mbox": "target-global-mbox",
12 "offer": offer
13 } );
14 },
15 "error": function(status, error) {
16 console.log('Error', status, error);
17 }
18});

Using custom timeout and custom success-handling with getOffer():

"YOUR_OWN_CUSTOM_HANDLING_FUNCTION" is a placeholder for a function the customer would define.

Copied to your clipboard
1adobe.target.getOffer({
2 "mbox": "target-global-mbox",
3 "success": function(offer) {
4 YOUR_OWN_CUSTOM_HANDLING_FUNCTION(offer);
5 },
6 "error": function(status, error) {
7 console.log('Error', status, error);
8 },
9 "timeout": 2000
10});

Responses#

The response parameter passed to the success callback will be an array of actions. An action is an object that usually has the following format:

NameTypeDescription
actionStringType of action to be applied to the identified element.
selectorStingRepresents a Sizzle selector.
cssSelectorStringDOM native selector, used for element pre-hiding.
contentStringThe content to be applied to the identified element.

Example#

Copied to your clipboard
1{
2 "sessionId": "1444512212156-384616",
3 "tntId": "1444512212156-384616.17_35",
4 "offers": [{
5 "plugins": ["<script type=\"text/javascript\">\r\n/*mboxHighlight+ (1of2) v1 ==> Response Plugin*/\r\nwindow.ttMETA=(typeof(window.ttMETA)!='undefined')?window.ttMETA:[];window.ttMETA.push({'mbox':'target-global-mbox','campaign':'at: redirect ootb','experience':'Experience B','offer':'/at_redirect_ootb/experiences/1/pages/0/1442082890250'});window.ttMBX=function(x){var mbxList=[];for(i=0;i<ttMETA.length;i++){if(ttMETA[i].mbox==x.getName()){mbxList.push(ttMETA[i])}}return mbxList[x.getId()]}\r\n</script>"],
6 "actions": {
7 "content": [{
8 "passMboxSession": false,
9 "selector": "body",
10 "action": "redirect",
11 "url": "https://example.com/04.html",
12 "includeAllUrlParameters": true
13 }]
14 }
15 }]
16}

Error Responses#

The "status" and "error" parameters passed to the error callback will have the following format:

NameTypeDescription
statusStringRepresents the error status. This parameter can have the following values:
  • timeout: Indicates that the request timed out.
  • parseerror: Indicates that the response could not be parsed, for example if we receive HTML or plain text instead of JSON.
  • error: Indicates a general error like we received HTTP status different from 200 OK
errorStringContains additional data like exception message or anything else that might be useful for troubleshooting.
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.