Highlighted

How to retrieve the environment name of Tealium in Extension?

Bronze Contributor
Bronze Contributor
So that it's feasible to do console.log(tealium.env) to print out the version in browsers. Thanks.
7 REPLIES 7
Highlighted

How to retrieve the environment name of Tealium in Extension?

Tealium Employee
Hi Marchi, This should do the trick for you. Jut add it to a JS extension scoped to All Tags. if(utag.cfg.path.indexOf("prod")>-1){ utag.data.env="prod"; }else if(utag.cfg.path.indexOf("qa")>-1){ utag.data.env="qa"; }else if(utag.cfg.path.indexOf("dev")>-1){ utag.data.env="dev"; } console.log(utag.data.env); Just curious, is there a specific need for this?
Highlighted

How to retrieve the environment name of Tealium in Extension?

Bronze Contributor
Bronze Contributor
Yes, there is. Currently we print out the latest Tealium version in browser log like this: cxTagLogger("Tealium Version - ##UTVERSION##") So would be even better if it can print out the Tealium Environment as well for diagnose purpose. Plus, we'd like to switch the Client ID of different tools(which is configured using JS Extension) using Tealium Environment instead of the actual running environment of the website itself.
Highlighted

How to retrieve the environment name of Tealium in Extension?

Tealium Employee
Understood, them my code above will provide the foundation for what you need. Let us know if you need any more help.
Highlighted

How to retrieve the environment name of Tealium in Extension?

Bronze Contributor
Bronze Contributor
Hi Dan, Is there any way to have this ready in "Preloader" stage? Seems we need this to be ready in advance to switch the Coremetrics base on Tealium environment.
Highlighted

How to retrieve the environment name of Tealium in Extension?

Tealium Employee
Hi Marchi, The utag object isn't available in Preloader. You could try to scrape the source code and grab the path of utag.js then parse out the environment.
Highlighted

How to retrieve the environment name of Tealium in Extension?

Bronze Contributor
Bronze Contributor
Hi Dan, I have tried all workaround to do the detection, but the ENV variable appeared rather lately... Ultimately we'd like to switch the Client IDs(especially Optimizely project ID) base on the Tealium environment instead of the actual running environment. Is there any way to have the server generated values in the sync.js & utag.js? e.g. ##UTENV## or ##UTPATH## Thanks. Marchi
Highlighted

How to retrieve the environment name of Tealium in Extension?

Tealium Employee
Hi Marchi, Since you are running Optimizely asynchronously, my initial code snippet scoped to All Tags will provide the environment before any tag is triggered. And actually, to make it a bit easier, you can leverage the following post which describes all the steps for how to complete your need: https://community.tealiumiq.com/posts/761868-how-to-change-tag-settings-based-on-tealium-environment