Create an mbox with at.js 2.x

Description

mboxCreate method doesn’t work with at.js 2.x
How could we create an mbox div at page level?

I tried with below code but no luck :

div class=“mboxDefault”
adobe.target.getOffer({
“mbox”: “customTestMbox”,
“params”: {
“status”: “true”
},
“success”: function(offer) {
adobe.target.applyOffer( {
“mbox”: “customTestMbox”,
“offer”: offer
} );
},
“error”: function(status, error) {
console.log(‘Error’, status, error);
}
});
/div

Resolution

Try closing your div tag before the script.

Sample:

div class="mboxDefault"
  default content to replace by offer
/div
script
  var el = document.currentScript.previousElementSibling;
  adobe.target.getOffer({
    mbox: "mboxName",
    params: {
      param1: "value1",
      param2: "value2"
    },
    success: function(offer) {
      adobe.target.applyOffer({
        mbox: "mboxName",
        selector: el,
        offer: offer
      });
    },
    error: function(error) {
      console.error(error);
      el.style.visibility = "visible";
    }
  });
/script

On this page