how to load js file and use functions from same file

Bronze Contributor
Bronze Contributor

Hi,

I am facing one issue with tealium custom container. I have added new tealium custom container template and loading js file from the template . Added another extension scope to after tags , when i try to call function from the js which i loaded from the template i am getting error saying that function not defined . i can see that function is not available by the time extension is loading . 

Is there any other solution in tealium to fix this issue ?

Thank you,

Veeru

 

 

 

 

 

 

5 REPLIES 5

how to load js file and use functions from same file

Tealium Expert
Tealium Expert

The delay is likely to be caused by either:

  1. The asynchronous loading of the tag file, or
  2. The asynchronous loading of the script

Or indeed both of those. Your best options, @vveerendra, are either to change the way in which the scripts are loaded (potentially bundling the tag into the main utag.js and loading the script in the container synchronously) or otherwise change the way in which you're trying to use the functions that the tag creates. If you're doing the latter, this might mean attaching the subsequent scripts to the onload attribute of the script you're adding, or polling for the existence of the required functions at intervals and holding off on using them until they're there.

how to load js file and use functions from same file

Tealium Employee
@vveerendra

Are you using u.loader to load your JS file?

If so, you can un-comment the u.loader_cb function and put your function calls where it says "Insert your post-Loader tag sending code here." These function calls will execute after your external JS file has loaded.

how to load js file and use functions from same file

Bronze Contributor
Bronze Contributor

I tried bundling the tag, @UnknownJ, but i am still seeing the same issue

how to load js file and use functions from same file

Bronze Contributor
Bronze Contributor

Hi @adam_wolfers,

I was able to fix using diffenent method . But i will also check your solution and let you in case of any issues.

Thanks!

how to load js file and use functions from same file

Employee Emeritus

Glad to hear that you fixed the issue using a different method @vveerendra. Would you mind replying and letting us know how you did it? I look forward to reading your approach. 

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better! Also remember that search is your friend.
Public