Highlighted

Set environment portion of utag dynamically?

Rookie Contributor
I've inherited an implementation. It seems we're setting the environment portion of the utag.js dynamically - we have a UDO variable set to JS: tealium_env = ((window.utag.cfg.path).split("/"))[6] And I'm guessing the code generating the tag is something like: tags.tiqcdn.com/utag/active/a3/+{utag_data.tealium_env}+/utag.js Is this good practice? Is there another/better way to do this? Thanks.
1 REPLY 1
Highlighted

Set environment portion of utag dynamically?

Tealium Employee

It sounds like your tealium_env variable is reading a value from the utag.cfg.path variable. This is no longer needed in latest utag.js template. You can use the new variable "ut.env" (add this in your Data Sources tab as a UDO variable) Some instructions here on updating your utag.js template to latest version: https://community.tealiumiq.com/posts/762863-how-do-i-upgrade-to-the-latest-utag-js On a related note.. You can dynamically tag your HTML source to load in the utag.js file from any location. // Code snippet on page var my_env_variable = 'prod'; (function(a,b,c,d){ a='//tags.tiqcdn.com/utag/myaccount/main/' + my_env_variable +'/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); })(); // Another option is use an extension to change environment based on domain // https://community.tealiumiq.com/t5/Tealium-iQ/Domain-Based-Deployment-Extension/ta-p/13703 // Domain-based deploy Extension means your tag will behave "as if" you coded this way a='//tags.tiqcdn.com/utag/myaccount/main/qa/utag.js