getOffer() Code - WebSDK vs AT.JS | Community
Skip to main content
Level 2
January 8, 2025
Solved

getOffer() Code - WebSDK vs AT.JS

  • January 8, 2025
  • 1 reply
  • 792 views

Hello, 

 

I was using at.js to get recommendation offers for my website. However, I was using the following code with at.js and I am not sure how to convert it to use webSDK.

 

### code ###
adobe.target.getOffer({ "mbox": "DemoBox2", "params":{ "entity.id":"target-global-mbox" }, "success": function(offer) { console.log("Result: "+offer[0].content); }, "error": function(status, error) { console.log('Error', status, error); } });

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vaibhav_Mathur

Hi @soufianela , 

In webSdk, you can use sendEvent command to request offers (propositions) for one or more locations (scopes). An alternate code for using getOffer() and applyOffer() in webSdk would be : 

alloy("sendEvent", { "decisionScopes": ["Homepage_regional_mbox"] }).then(function(result) { var retrievedPropositions = result.propositions; // Render offer (proposition) to the #hero-banner selector by supplying extra metadata return alloy("applyPropositions", { "propositions": retrievedPropositions, "metadata": { // Specify each regional mbox or scope name along with a selector and actionType "Homepage_regional_mbox": { "selector": ".tracking-tight", "actionType": "replaceHtml" } } }).then(function(applyPropositionsResult) { var renderedPropositions = applyPropositionsResult.propositions; // Send the display notifications via sendEvent command alloy("sendEvent", { "xdm": { "eventType": "decisioning.propositionDisplay", "_experience": { "decisioning": { "propositions": renderedPropositions } } } }); }); });


For more such codes related to at.js VS webSDK , you can feel free to use this cheatsheet : https://dexata.co/adobe-target-commands-profilescripts-cheatsheet/  

Best Regards,
Vaibhav Mathur

1 reply

Vaibhav_Mathur
Community Advisor
Vaibhav_MathurCommunity AdvisorAccepted solution
Community Advisor
January 8, 2025

Hi @soufianela , 

In webSdk, you can use sendEvent command to request offers (propositions) for one or more locations (scopes). An alternate code for using getOffer() and applyOffer() in webSdk would be : 

alloy("sendEvent", { "decisionScopes": ["Homepage_regional_mbox"] }).then(function(result) { var retrievedPropositions = result.propositions; // Render offer (proposition) to the #hero-banner selector by supplying extra metadata return alloy("applyPropositions", { "propositions": retrievedPropositions, "metadata": { // Specify each regional mbox or scope name along with a selector and actionType "Homepage_regional_mbox": { "selector": ".tracking-tight", "actionType": "replaceHtml" } } }).then(function(applyPropositionsResult) { var renderedPropositions = applyPropositionsResult.propositions; // Send the display notifications via sendEvent command alloy("sendEvent", { "xdm": { "eventType": "decisioning.propositionDisplay", "_experience": { "decisioning": { "propositions": renderedPropositions } } } }); }); });


For more such codes related to at.js VS webSDK , you can feel free to use this cheatsheet : https://dexata.co/adobe-target-commands-profilescripts-cheatsheet/  

Best Regards,
Vaibhav Mathur