Data Layer Object (b)
Learn to use the alias to the Data Layer Object (b
).
What is the b
Object?
The b
object is a JavaScript variable containing the most recent copy of the data layer object. Depending on when it’s referenced, the b
object is either an alias or a local copy of the utag.data
object. So what is the utag.data
object? The utag.data
object is a collection of all the data on your page:
- Data Layer Variables
- JavaScript Page Variables
- Meta Tags
- DOM Attributes
- Cookies
So, in essence, the b
object is a copy of your page’s data layer.
Why Do We Have a b
Object?
Using the b
object provides a couple benefits:
- As an alias with a shorter name
This shorter name improves performance loading Tealium. If you had to referenceutag.data
a hundred times, then you are adding 900 characters to the size of your files. That’s 900 more characters the browser has to parse through when loading these files which results in a negative affect on visitor load times. Referring to it asb
means only 1 character to add to the file for each reference, which if you referenced a hundred times results in only 100 characters for the browser to parse through. - As a copy that leaves the original untouched
By creating a local copy ofutag.data
, the values needed for each tag are customizable without affecting the original data object.
Variable Types
To reference a variable in the b
object directly in a tag template or extension, you must consider the type of variable you’re trying to reference; the syntax differs slightly.
Data Layer
For variables contained in the utag_data
object, use the following syntax:
b['var_name']
JavaScript Page Variable
To reference variables defined as JavaScript Page variables, use the following syntax:
b['js_page.var_name']
Query String Parameters
To reference a query string parameter, use the following syntax:
b['qp.var_name']
Cookie Values
Tealium has two ways to store cookie values. The syntax to reference these two types varies slightly. Learn more about working with cookies in Tealium iQ.
-
utag_main
Cookie Values - to reference a cookie value contained in theutag_main
cookie, use the following syntax:b['cp.utag_main_var_name']
-
Standard Cookie Values - to reference a cookie value that is not contained in the
utag_main
cookie, use the following syntax:b['cp.var_name']
Additional Considerations
The b
object is not global
- The
b
object is a locally scoped variable, only available in All Tags and Tag Scoped extensions. - Extensions scoped to Pre Loader run before the
b
object has been created. - Extensions scoped to DOM Ready run independently from the main order of operations, so the
b
object cannot be referenced in this scope either. - Learn more about how to reference the data object variable in extensions.
The b
object in tracking calls
- During a standard page load, the
b
object becomes a copy of theutag_data
object. However, on manual tracking calls, theb
object is a copy of the object passed toutag.view()
orutag.link()
and does not contain variables from the originalutag_data
object. - To preserve data from
utag_data
in tracking calls (per page load) use the Base Variables setting in the publish settings.
For profiles loading version 4.39 or older, the content of the b
object during tracking calls is a complete copy of utag.data
. Learn more about this update in release history utag.js
4.40.
This page was last updated: January 7, 2023