Injecting custom code from Target with calls to backend | Community
Skip to main content
Level 2
January 14, 2020
Solved

Injecting custom code from Target with calls to backend

  • January 14, 2020
  • 3 replies
  • 7144 views

Hi,

 

We sometimes inject custom code (ie: offer or banner) into our website that have backend calls to display dynamic data (not Adobe related). The issue we currently have is that because the webpage and the Target injection happen async, sometimes (especially on first load in all browsers, and in IE11) Target code is injected before the page finishes loading all the JS, causing the dynamic data not to show. The only way we are able to get around this issue is to set a timeout in the Target custom code of 3+ seconds so that Target holds on injecting the code until most or all of the page JS is loaded. This is not great for performance.

 

Is there a way through Target to wait until page load is complete before Target code is injected? or can you suggest a way to get around this issue?

 

Thanks!

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 Gaureshk_Kodag

I dont think target have any inbuilt functionality like this. Also setTimeout can fail in some cases like page not loaded within 3 secs. You can try using setInterval or page load event to fire your code.

3 replies

Gaureshk_Kodag
Adobe Employee
Gaureshk_KodagAdobe EmployeeAccepted solution
Adobe Employee
January 15, 2020

I dont think target have any inbuilt functionality like this. Also setTimeout can fail in some cases like page not loaded within 3 secs. You can try using setInterval or page load event to fire your code.

LucasSAndrade
Level 2
February 14, 2020

Hello @amazi 

 

In my scenarios when Target needs to comunicate with back end. I usually aks for devs in my team to make elements in front to comunicate with back end. 

For example a button that makes a request to back end, soo front help me with the load time, ensurring that all scripts are loaded.

 

But its hard sometimes. You will have to adjust with each scenario 

AmaziAuthor
Level 2
February 25, 2020

Hi @lucassandrade,

That's what I ended up doing. Our front-end dev made all the functions available in the main html and target uses them afterwards. The issue with this is every time we need new functionality, we have to ask them to do develop it first before our team has to use it. In any case, this is the only way we were able to work out this scenario.