- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
03-11-2015 08:46 AM - last edited on 10-07-2015 12:47 PM by kathleen_jo
I would like to use utag.link() to send Tealium events for internal promotions once the DOM has loaded on a given page like:
jQuery(document).ready(function() {
utag.link({data goes here});
}
(I made sure that this loads towards the end of the page)
At the time of execution, utag isn't available yet and hence its throws a "utag is not defined" error.
Is there a way to execute such code when "utag" is available? perhaps a callback function from utag.js?
Please advise.
03-11-2015 11:32 AM - last edited on 10-07-2015 12:47 PM by kathleen_jo
You can use:
jQuery(window).load(function(){
utag.link({data goes here});
}
03-11-2015 11:59 AM - last edited on 10-07-2015 12:49 PM by kathleen_jo
I have read that window.load may not be consistent across browsers, especially considering mobile browsers.
I am using the following approach currently:
// when utag.js is available within page source, trigger utag.link calls
jQuery('script[src*="utag.js"]').on('load', function() {
// utag.link calls here...
});
03-11-2015 02:58 PM - last edited on 10-07-2015 12:49 PM by kathleen_jo
If you have the ability to edit source code on your page, something like this could work:
http://stackoverflow.com/questions/20492677/loading-asynchronous-js-file-readystate
Basically editing the way you load utag.js and firing a callback. The method you suggested would run into issues if somehow it executed after utag.js finished loaded before that statement is even reached (a real possibility with file caching). The 'load' would never trigger because it's already loaded.
Copyright All Rights Reserved © 2008-2023