Extension Function loading delay issue

Bronze Contributor
Bronze Contributor

Hi Team,

I had a requirement where I need a custom event fired if there are multiple vehichle policy for a customer.

So in the web page on page load developers create a java object and call the extension function processCustomEvent(data)  which just eventually calls the utag.link(data) after some personal data validations.

var data = {
"event_name": "Vehicle count Track",
"event_parent": "Page Tag",
"event_type: "xxx",
"event_id": " yyy",
"event_value": count of vehicle,

Now they asked to ensure  if the extension gets loaded in the page when this call is made. 

My question is `- 

1) As utag.js is placed in the top of the body tag of web page and is loaded asynchronosly. Does that can really cause the extension function processCustomEvent(data) in page load can happen before the function is loaded by utag.js

2) If Yes what is the best approach to ensure this doesnt happen? 

For the time being I fixed this by addding a scrip in page 

function processCustomEventAfterLoad (data) {
        if (window.processCustomEvent) {
           window.processCustomEvent (data);
        } else {
             setTimeout(() => { processCustomEventAfterLoad(data); }, 200);

But is this best solution ? is there any other Telium magic ways to ensure all the calls can happen only after the functions are fully loaded by async loading of utag.js