Highlighted

Extension that runs on utag ready

Silver Contributor
Silver Contributor

In the current scoping options for extensions (specifically javascript extensions) we have the option to choose preloader which executes prior to utag being defined. Any call to utag functions (eg. utag.DB) will obviously fail. If choosing the scope of all tags, the extension is ran at every call to utag.view/link but the utag.DB works.

 

The usecase I am working on requires me to use a js extension that runs only once but has utag allready defined. To clarify I would need a scope of utag ready which executes after preloader but before the all tags extensions(if any).

 

This seems a lot like a feature request and my usecase might be less important for other customers but having a scope which only runs once after the core of tealium is loaded might superced the usage of preloader in a lot of cases and would enable me to (re)use functions in in the tealium code.

Currently I have a working POC which polls the availability of utag ,utag.handler && utag.handler.iflag which seems to be a crazy hack but works nicely

 

code:

 

waitUntil(
   function checkforutagavailability(){
      return utag && utag.handler && utag.handler.iflag === 1
   }
   ,runother function
   ,20
   ,1000
);

 

where watUnitll checks every 20ms if the utag && utag.handler etc is available and runs at maximum for 1second or calls the runotherfunction if the validation works.

 

Is this a plausible solution, do you have any other idea and is there any chance whether this type of 'scope' could be a feature in Tealium?

4 REPLIES 4
Highlighted

Extension that runs on utag ready

Employee Emeritus

@jan_van_damme


Great question and I am sure there are many ways to approace the solution. The most common way would be the following:

 

if(typeof utag.runonce['my_code_init'] === 'undefined'){
  utag.runonce['my_code_init'] = true;
  // run the rest of your code here.
  // your code will only run once because of the if block
}

 

Highlighted

Extension that runs on utag ready

Silver Contributor
Silver Contributor
The problem is not running it once as this can be easily done but the condition is more strict in that I need to know when utag is available but the soltion should not be scoped as an all tags extension. I guess i'll have to digg a bit deeper or rework the solution to not need the utag dependencie.

Thanks anyways
Highlighted

Extension that runs on utag ready

Silver Contributor
Silver Contributor

Still no answer for this?

Highlighted

Extension that runs on utag ready

Employee Emeritus

@richard_udovich and @jan_van_damme

If you scope to "All Tags" or "DOM Ready" then utag will be available.  The only scope that will not have utag is "Pre Loader".  If you need this extension to run first, then you can move it up higher in the list of extensions (you can drag and drop the extensions to change the execution order). 

 

Also you can Scope to "All Tags" - "Before Load Rules" which run before the default "After Load Rules"


Hope this helps.

 

If not, reach out by opening a support case and one of our engineers can work with you on your specific website:

https://community.tealiumiq.com/t5/custom/page/page-id/support-contact-form