How do I retrieve content using applyOffers()? | Community
Skip to main content
Level 3
April 21, 2021
Solved

How do I retrieve content using applyOffers()?

  • April 21, 2021
  • 2 replies
  • 1951 views

Hi

I have a secure SPA that we're implementing Target into.  We've decided to utilise the new getOffers() and applyOffers() functions that were part of at.js 2x.

Via a Launch rule we have managed to successfully 'get' the offers, i.e., see the offers associated with the mbox in the response, this is code we've used to do this..

However, I've been unable to figure out how to apply any of these offers, the Adobe documentation is a bit sparse, giving no example of how to retrieve the content associated with the mbox, I've attempted the below, which haven't retrieved anything:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Is anybody able to give me any pointers, or examples of the correct syntax I should be using?

Many thanks

Dan

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 dan_e1982

I have managed to answer my own question.

 

First of all I run the getOffers() code, however I save the response into a custom Launch variable "resObj", this allows me to split the running of getOffers() and applyOffers()

 

 

To apply the content within this "resObj", I run a for loop to find the mbox content I want to apply.   To easier facilitate this the mbox name I've applied in Target matches the analytics page name ("page|name").

 

mboxOffer then has the specific content of the mbox parsed into it, which can then be placed with the applyOffers() call

 

This solution enables me to split the two functions, and refer directly to the response offer, something I've not been able to find in the Target documentation.

 

Hope this is useful to anybody else attempting to do this, I'd be interested to know whether anybody else in the community has come up with an alternative way to do this.

 

Dan

2 replies

Pawan-Gupta
Level 8
April 23, 2021

Hello,

Is there any specific reason you are trying to execute applyOffer separately?? because ideally it should be working with getOffer after receiving the response. I hope you must have referred https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/at-js-implementation/functions-overview/adobe-target-applyoffer.html?lang=en#implement-target or https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/at-js-implementation/functions-overview/adobe-target-applyoffers-atjs-2.html?lang=en#implement-target 

 

based on at.js (1.x or 2.x) respectively.

 

and if you are using mbox.js then i think applyOffer doesn't supported there, refer - https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/mbox-implement/mboxjs-functions.html?lang=en#implement-target 

dan_e1982Author
Level 3
April 26, 2021

Hi

 

We're using the at.js (2x) library.

 

The idea of using getOffers() was to retrieve/prefetch all offers in the one call, in my case, on the load of the SPA. 

 

Then, as the user went through the different states of the SPA, executing the applyOffers() function to retrieve the relevant offer from the response as and when needed, I assume the response is held somewhere in cache.

 

If we have to run the functions together i.e. getOffers() then immediately applyOffers(), then this offers no difference in functionality to the old getOffer()-> applyOffer() functions in at.js (1.x)..... for how I wish to use it anyway!

 

 

dan_e1982AuthorAccepted solution
Level 3
May 2, 2021

I have managed to answer my own question.

 

First of all I run the getOffers() code, however I save the response into a custom Launch variable "resObj", this allows me to split the running of getOffers() and applyOffers()

 

 

To apply the content within this "resObj", I run a for loop to find the mbox content I want to apply.   To easier facilitate this the mbox name I've applied in Target matches the analytics page name ("page|name").

 

mboxOffer then has the specific content of the mbox parsed into it, which can then be placed with the applyOffers() call

 

This solution enables me to split the two functions, and refer directly to the response offer, something I've not been able to find in the Target documentation.

 

Hope this is useful to anybody else attempting to do this, I'd be interested to know whether anybody else in the community has come up with an alternative way to do this.

 

Dan

Level 2
August 17, 2021

I am having the same issue. I am trying to apply a JSON Offer and am wondering if that is my issue.

Was your offer an HTML offer or a JSON offer?