Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 2

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
Community Advisor

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

0 Replies

Avatar

Correct answer by
Community Advisor

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 2

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...