- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
06-09-2023 08:17 AM
One of our application team is trying to block the default view call and fire it inside their app. When we attempt to run the blow code we are getting 'utag is not defined' error on the console.
Can you please help to suggest on what we are missing here.
Thanks,
Jay
06-09-2023 09:30 AM
The issue you're encountering, "utag is not defined," often occurs when you're trying to use the utag object before it has been fully loaded and initialized. This is a timing issue. Your code attempts to access the utag object immediately after the script tag to load utag.js has been inserted into the page. However, the script is loaded asynchronously, meaning it may not be fully loaded and executed by the time your code runs.
Try adjusting your code to ensure that the utag object is defined before you try to use it. You could accomplish this by adding an event listener for the load event of the script tag. When the load event fires, it signifies that the script has been fully loaded and executed, so utag should now be defined.
Here's a sample code snippet:"
(function(a,b,c,d){
a='//tags.tiqcdn.com/utag/aa/amadeus/'+ detect platform()+ '/utag.js';
b=document; c='script';
d=b.createElement(c);
d.src=a;
d.type="text/java"+c;
d.async=true;
a=b.getElementsByTagName(c)[0];
a.parentNode.insertBefore(d,a);
// Add event listener for the load event of the script
d.addEventListener('load', function() {
// Block the default view call
window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.noview= true;
console.log("Set the noview to true!");
if (utag) {
utag.view(utag_data);
console.log("utag.view call fired!");
}
});
})();
Please note that this code still assumes that detect platform() and utag_data are properly defined elsewhere in your code. If they are not, you may still encounter errors.
Remember to test this code thoroughly in a development environment before deploying to production.
06-12-2023 09:51 AM
Yes, platform() and utag_data are defined in the code. Thank you so much.
I will give it a try and let you know.
Copyright All Rights Reserved © 2008-2023