How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Bronze Contributor
Bronze Contributor
 
5 REPLIES 5

How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Employee Emeritus

Hi Yuen, Depending on when you call utag.js (i.e. Tealium) and what version of Tealium you are using - the utag.link() event may or may not be able to be called quickly enough. However, to stand the best chance of being able to call it: 1. Upgrade to the latest Tealium version like this: https://community.tealiumiq.com/t5/uTag/How-do-I-upgrade-to-the-latest-utag-js/ta-p/5042 2. Ensure utag.js is called at the top of the as recommended In order for utag.link() to work, Tealium needs to have initialised the 'utag.link()' function in utag.js. However, as most implementations now are asynchronous, there's no guarantee that by the time you want to call it - it will exist (if you want to call it extremely quickly as you do in this scenario). One option would be to load utag.js synchronously (see code center : https://community.tealiumiq.com/t5/Tealium-iQ/Code-Center/ta-p/13631 - this way utag.link() will definitely be available to be called at any point past the utag.js call. However, this is not recommended as utag.js doesn't need to block the page - it's best to be called asynchronously. This might not be the answer you are looking for but unfortunately for technical reasons it's not possible to call utag.link() unless you know that it has been initialised. I hope this helps. Cheers, Roshan

How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Employee Emeritus
If you have jQuery, you can replace the code to load the Tealium utag.js library with code that has a call back. Then add the utag.link call to the callback. Something like the following: //https://api.jquery.com/jquery.getscript/ jQuery.getScript( "https://tags.tiqcdn.com/utag/account/profile/environment/utag.js", function( data, textStatus, jqxhr ) { //console.log( data ); // Data returned //console.log( textStatus ); // Success //console.log( jqxhr.status ); // 200 //console.log( "Load was performed." ); utag.link({ "event_name":"some_event_name", "key1":"value1" }); });

How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Bronze Contributor
Bronze Contributor
That would work. However, Tealium would now be dependent on jQuery to load first, and everything would start to load slower because of this. The two solutions I have thought of is 1 - to create a queue that gets read by Tealium once it has loaded; and sending utag.link/view into the queue; 2 - or to have a setTimeout loop that checks if Tealium has loaded before firing. Either solution is not ideal if Tealium already has a workaround/solution that I'm not aware of. As for the earlier solution of firing Tealium synchronously is a huge debate on it's own. Thanks though!

How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Employee Emeritus
Good point. Instead of loading the whole jQuery library to use one piece of functionality, just hard code their solution. Something like: http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer Read all the comments, there is some good advice in the their for you to think about as you come up with the best solution for your environment. Happy tracking.

How can I track an Event upon page load?I want to call utag.link(...) after the page has loaded, but Tealium isn't picking the utag.link(...) function yet.

Employee Emeritus
Hi Tim, Yes, you're right. I've come across this issue before. Doing the setTimeout isn't ideal as you say but the queue is a good idea. I wrote something like this a while ago and I've just re-jigged it. Here it is: Run this as an extension: http://snipsave.com/user/profile/roshangonsalkora#10765 Run this code in-line to queue calls (or fire them immediately if utag.view() or utag.link() exist): http://snipsave.com/user/profile/roshangonsalkora#10764 I hope this helps! Cheers, Roshan
Public