Highlighted

utag.js code snippets

shwetabakshi
Visitor
shwetabakshi

Please help me understand what :

u.extend[function(a,b){}]; and    utag.loader.EV(",'ready',function(a){};)

1 REPLY 1

utag.js code snippets

UnknownJ
Occasional Contributor
UnknownJ Occasional Contributor

Hi @shwetabakshi

u.extend works in the same way that utag.handler.extend does, except without the need for a matching configuration object because the only extensions that are stored in there are the tag-scoped extensions for the tag in question (the contents of u.extend are generally found in a specific utag.x.js file, as opposed to the main utag.js (unless your tags are bundled))

When an event is sent to a tag, prior to undertaking the mapping process, the tag template will iterate over u.extend and run the functions within against the tag's local copy of the event payload prior to data being mapped. An example from the Tealium Learning Community would be utag.sender[21].extend[2], which runs:

function(a,b){
  try{
    if(b['tealium_event']=='item_pressed'){
      b['ga_event_category']='Custom_Click';
      b['ga_event_action']=b['item_area'];
      b['ga_event_label']=b['item_name']
    }
  }catch(e){
    utag.DB(e)
  }
}

And maps a couple of generic variables to specific Google Analytics variables, ready to then be mapped into the tag.

Then utag.loader.EV is a function that usually adds an event listener to an object, thus:

utag.loader.EV = function(target_object, event_type, handler_function){ ... }

However, if event_type above is "ready", then it sets the handler function to run at DOM Ready, which is either almost immediately (sets a timeout for 1ms) if the page has already loaded, or otherwise the functon is passed into a queue (the array utag.loader.ready_q) and an event listener set against the DOMContentLoaded event against the document to run through it (the function utag.loader.run_ready_q). This is how DOM Ready scoped extensions are executed, so you should see a utag.loader.EV call for each DOM Ready extension that you've got. There are some features of Tealium that also run at DOMContentLoaded, so there will be elements in the queue that weren't derived from extensions as well.