How to use Scope Vars

sam_tsai
Rookie Contributor
sam_tsai
One of the features of the Javascript extension in Tealium's that I find ambiguous is how to use the "Scope Vars" or even know which variable name associates with what object. I think through trial and error I discovered that `b` represents the utag_data object so in some cases I reference it directly: `code b.page_name = "test"; ` This feels dangerous, especially if Tealium changes the variable at some point. And also, with the "scope vars" field, how do you actually use it?
5 REPLIES 5

How to use Scope Vars

Tealium Employee
Scope Vars is a legacy feature for the Javascript Extension "syntax checker." For example, you might put "b" in there to tell the syntax checker that "b" is already defined. I believe the syntax checker no longer looks for variables out of scope so this feature will most likely be removed from the UI eventually. Regarding the "b" variable. The b variable is the tag's local copy of the utag.data object. This variable is safe to use and not go away or change at some point.

How to use Scope Vars

sam_tsai
Rookie Contributor
sam_tsai
Thanks @Ty, other than debugging the Tealium source code and setting breakpoints are there quicker/easier ways to determine the variable mappings - so that you could easily find what local copies map to what? Does that make sense?

How to use Scope Vars

Tealium Employee
I expect that we'll see more features in Tealium Web Companion around this. One thing you can do is add a Javascript Extension and scope to your tag with the following code: utag.DB(b); This will output the "b" object to your console. That may be a little quicker to debug than setting breakpoints. To enable debugging, set this cookie: document.cookie="utagdb=true";

How to use Scope Vars

jon_williams
Employee Emeritus
jon_williams
Hey Sam, If you mean mappings you can go to the Tag tab, then go the tag you're interested in and select Edit in the Mapping Data Sources box. Here you will see the tealium variables to that specific tag variables mapping.
Highlighted

How to use Scope Vars

sam_tsai
Rookie Contributor
sam_tsai
Hey Jon, Good to put a face to the name. When I said variable mappings I meant it more generally. For example, "b" maps to the local copy of the `utag_data` object within utag.js.