Uncaught TypeError: utag.link is not a function

Bronze Contributor
Bronze Contributor

I seem to be noticing a lot of error with out utag.js inject/implemention on out site. 
This uncaught error seem to occur everytime we reload a page.

This is in particular a problem as this interfer with the way we track videos.. 

We are using the async script, and have tried putting on head, body , bottom of body and top of body.. 
But nothing seem to give me a consistent result.. 

Somehow I can assure that this is will be created/executed at all time?

 

 

1 REPLY 1

Uncaught TypeError: utag.link is not a function

Employee Emeritus

Hi @Kiddi,

Thanks for getting in touch. From your description, it seems that you are sending a tracking call before utag has completely initialised.

You could queue all events until utag is loaded. Credit to one of our former colleagues Brian Kranson for the following code:

//Inline on the page
(
function(t,e,a,l,i,u,m){ if(t.utag)return;e=t.utag={};e.e=[]; e.view=function(a,b,c){e.e.push({a:a,b:b,c:c,d:"view"})}; e.link=function(a,b,c){e.e.push({a:a,b:b,c:c,d:"link"})}; e.track=function(a){e.e.push({a:a.data,b:(a.cfg?a.cfg.cb:null),c:(a.cfg?a.cfg.uids:undefined),d:a.event})}; }(window));

 

// Very first preloader code
// put the utag_events into the window scope as utag_events
// then delete utag so that the utag.js will build up as needed
(function(w){
    if(typeof w.utag !== 'undefined' && typeof w.utag.e === 'object'){
        w.utag_events = w.utag.e;
        delete w.utag;
    }
}(window))

 

// DOM Ready Extension
// loop through the window level array utag_events and call utag.track as necessary
// utag.track will use the view or link or any event as well as the callback or list of tag ids (function(w){ if((typeof w.utag_events === 'object' && w.utag_events.length > 0)){ while(w.utag_events.length){ d=w.utag_events.shift(); (function(d){ setTimeout(function(){ utag.track({ event: d.d, data: d.a, cfg: { cb: d.b, uids: d.c } }); }, 150); })(d); } } }(window))
 

Hope you find this useful.

Regards,

Ribal

Public