utag_data object declaration

Silver Contributor
Silver Contributor

Hi all,

I have a very minor problem, but it does interest me: Not all variables that I use in iQ are declared in the script that is part of the HTML-code. So there are some elements in utag_data that are not declared from the very start of the page loading.

This does not seem to create any problem yet, but I get nasty error messages in the output of the debug mode. So I wanted to get rid of them. I found two rather simple solutions, which are both quite similar. First, I've declared the variables in the beginning of utag.sync, which I am fortunate having as part of the setup. The other try was to use a JS-extension that does pretty much the same and I've scoped it to pre loader.

This works quite well - the error messages disappear from the debug output on the console, but only when it's a page load. When any event is triggered, the errors are back.

I just can't figure it out why this happens - the variables should be declared, so why are they not valid in the event scope?

Thanks for your ideas and help!

Best regards,

Bernd

4 REPLIES 4

utag_data object declaration

Tealium Employee

Hi @sangmister,

Without seeing the actual error messages I'll just throw this possibility out to you. An example of such an error might be 

image2.png

Tealium will catch errors when a method is applied to a variable that is undefined. This will occur for any test on conditions within Load Rules and Extensions

 image1.png

Best practice is to first test for the variable to be defined, e.g., 

image3.png

Doing this will help to avoid these errors in the Console. 

Thanks, David

 

utag_data object declaration

Silver Contributor
Silver Contributor

Hi David,

thanks for taking the time to answer!

Unfortunately, I've tried your approach but still have these errors:

defining_vars_in_tealium.jpg

I've also tried declaring the variables in an extension, like b['page_name'] = "" but that didn't get me rid of the errors as well.

Do you have another idea why that happens?

Thanks and best regards,

Bernd

utag_data object declaration

Tealium Employee

Hi Bernd,

I believe this is occurring in your example because of the order of the tests. The .toString() on the undefined parameter is occurring before the test to see if it is defined.

Ensure the 'is defined' test on the parameter is listed first in the conditions within your extension or JS code:

image3.png

If that doesn't work for you please file a ticket with support@tealium.com so we can take a look for you. 

Thanks, David

utag_data object declaration

Silver Contributor
Silver Contributor

Thanks, @david_bird! That did it!!

PS. Now I know, why the JavaScript-Editor gives the hint "variable is better written in dot notation"... ;)

Public