Expand my Community achievements bar.

SOLVED

Using adobe.target.getOffer , the result does not execute

Avatar

Level 2

Using adobe.target.getOffer, success or failure doesn't console.log anything. All relevant offers have been configured. Please see what the problem is, thanks a lot.

 

console.log('getOffer begin:') is printed, but the success or error console is not executed.

截屏2023-02-11 01.39.15.png

console.log("getOffer begin:");
adobe.target.getOffer({   
  "mbox": "locationA", 
  "success": function(offer) {           
      adobe.target.applyOffer({  
         "mbox": "locationA", 
         "offer": offer  
      }); 
      console.log("Get offer success : ", offer);
  },   
  "error": function(status, error) {           
      console.log('Error', status, error); 
  },
  "timeout": 3000
});

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @yan_yan,
Here is also an overview of how I created a test activity for it:

 

Location 1

target-global-mbox

Content

<script>
adobe.target.getOffer({
  "mbox": "locationA",
  "success": function (offer) {
    if (offer.length) { 
      adobe.target.applyOffer({
        "mbox": "locationA",
        "offer": offer
      });
      console.log("Get offer success : ", offer);
    } else {
      console.log('Offer not available');
    }
    
  },
  "error": function (status, error) {
    console.log('Error', status, error);
  },
  "timeout": 3000
});
</script>

 

Location 2

locationA

Content

<script>console.log("Offer locationA")</script>

 

-> Console Output:

  • Offer locationA
  • Get offer success : [{...}]

If there was no offer or default content stored for location 2 - it would look like this in the console:

 

-> Console Output:

  • Offer not available

 

Hope this helps you.

 

Best regards

View solution in original post

4 Replies

Avatar

Community Advisor

 

 

Hello @yan_yan,
I recommend to check the offer again if the e.g. is empty - can also be checked more precisely. But here is an example of what I mean:

adobe.target.getOffer({
  "mbox": "locationA",
  "success": function (offer) {
    if (offer.length) { 
      adobe.target.applyOffer({
        "mbox": "locationA",
        "offer": offer
      });
      console.log("Get offer success : ", offer);
    } else {
      console.log('Offer not available');
    }
    
  },
  "error": function (status, error) {
    console.log('Error', status, error);
  },
  "timeout": 3000
});

You can of course check with offer[0].content - even more - if desired. But basically you can see here if the expected offer arrives at all.

 

Hope this helps you.

Avatar

Level 2

hi @Perrin_Ennen ,

Thank you for your reply. I tried, but I still can't print the console in Success or Failure.

Avatar

Correct answer by
Community Advisor

Hello @yan_yan,
Here is also an overview of how I created a test activity for it:

 

Location 1

target-global-mbox

Content

<script>
adobe.target.getOffer({
  "mbox": "locationA",
  "success": function (offer) {
    if (offer.length) { 
      adobe.target.applyOffer({
        "mbox": "locationA",
        "offer": offer
      });
      console.log("Get offer success : ", offer);
    } else {
      console.log('Offer not available');
    }
    
  },
  "error": function (status, error) {
    console.log('Error', status, error);
  },
  "timeout": 3000
});
</script>

 

Location 2

locationA

Content

<script>console.log("Offer locationA")</script>

 

-> Console Output:

  • Offer locationA
  • Get offer success : [{...}]

If there was no offer or default content stored for location 2 - it would look like this in the console:

 

-> Console Output:

  • Offer not available

 

Hope this helps you.

 

Best regards

Avatar

Administrator

Hi @yan_yan , thanks for your question!

Did you find @Perrin_Ennen's answer helpful? If so please feel free to mark his reply as "Correct" and/ or follow up with a question or more context   Thanks so much to you both for your Adobe Target expertise and dedication!