Expand my Community achievements bar.

Join us for an upcoming in-person Adobe Target Skill Builders event ~~> We're hosting these live learning opportunities to equip you with the knowledge and skills to leverage Target successfully. Learn more to see if we'll be coming to a city near you!
SOLVED

Is there an event we can listen to so we know when adobe target scripts are done loading? For SPA..

Avatar

Level 3

We have a react SPA.  First page that the user goes to, it seems the "adobe" object is available, but target.getJsonOffer() is not there yet.  Eventually it is there and we can execute it but not unless we do some sort of timeout functionality or force the SPA to re-render.  

Is there some sort of mechanism to knowing when the getJsonOffer, triggerView, etc. functions are available so we can start firing them?

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hello,

 

I think, it should be other way around because target response is asynchronous you should be looking from page or component load side (same we have done in our side as well)

 

as and example refer - https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/at-js-implementati...

as it rightly called out, how it should be done.

 

Hope it helps!!

View solution in original post

4 Replies

Avatar

Correct answer by
Level 9

Hello,

 

I think, it should be other way around because target response is asynchronous you should be looking from page or component load side (same we have done in our side as well)

 

as and example refer - https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/at-js-implementati...

as it rightly called out, how it should be done.

 

Hope it helps!!

Avatar

Level 3
Sorry, posted a separate 'answer' as my reply. Please take a look.

Avatar

Level 3

Not 100% sure I'm following.  I can't even exectue the getJsonOffers() function to use its asynchronous functionality.  As you can see in the screenshot - adobeVailable() function checks for adobe.target and adobe.target.getJsonOffer.  As you can see, even the 'target' property isn't there yet for me to execute, thus it would cause runtime errors if I tried to.

jchabot86_0-1623084316854.png

 

Avatar

Level 2

I think the at-library-loaded event should do the trick.

 

Library Loaded
Constant: adobe.target.event.LIBRARY_LOADED
String Value: at-library-loaded
Description: This event is ideal to track when at.js has been fully loaded. You can use this event to customize global mbox execution. You can also use this event to disable the global mbox and then listen for this event to fire the global mbox later.
https://experienceleague.adobe.com/docs/target/using/implement-target/client-side/at-js-implementati...