Highlighted

How can I access ut.env in Pre-Loader Scope?

Silver Contributor
Silver Contributor

For some debugging purposes, it is helpful to send error messages to our error tracking tool or the console, but we want to do this only on non-production environments for most errors.

 

So usually we refer to a function that does this logging for us depending on whether window.console is not undefined and whether we are not on production (utag.data["ut.env"] !== "prod").

 

In Pre-Loader Scope, ut.env is not available. What ways do I have to check what environment I am on there?

3 REPLIES 3
Highlighted

How can I access ut.env in Pre-Loader Scope?

Tealium Employee

Hi @loldenburg

 

That is correct, Pre-loader scoped extensions are ran before the Tealium library runs so utag is unavailable.

 

You would need custom code to scrape the page and check for /dev/ or /qa/ utag.js. Something like:

 

a=document.getElementsByTagName("script");
for (var i=0; i<a.length; i++){
if(a[i].src.indexOf("/dev/utag.js") > 0 || a[i].src.indexOf("/qa/utag.js") > 0) {
console.log(a[i].src);
}
}

 

Hope this is helpful.

 

Cheers,

-Dan

Highlighted

How can I access ut.env in Pre-Loader Scope?

Silver Contributor
Silver Contributor
HI @dan_george, thanks, that is of course quite some workaround, it also does not work when switching environments with a proxy, but it is better than nothing. If there is a proxy-compliant way of doing it, let me know.
Highlighted

How can I access ut.env in Pre-Loader Scope?

Tealium Expert
Tealium Expert

Hi @loldenburg, you may want to try using the following to grab the current environment from a Pre-Loader Scoped Extension.

 

window["utag_data"] = window["utag_data"] || {};
window["utag_data"]["tealium_env"] = document.currentScript.src.split('/').reverse()[1];

 

This should be pretty compatible these last days , except for IE (#sigh), you may rely on the getElementsByTagName('script') as failover if document.currentScript is undefined for some reason.