Data layer best practices
This article reviews our best practices for implementing and managing your data layer.
In the page code, the data layer object (
utag_data) must be declared before the reference to the Universal Tag (
utag.js). This ensures that the Universal Tag has all the data layer variables needed to evaluate load rules, extensions, and tags. An example of the recommended code placement can be accessed from the Code Center.
Learn More: Code Center
The goal of the data layer is to provide a set of variables that are vendor-neutral and easy to understand. The following best practices apply:
- Use lowercase, underscore-separated variable names.
- Avoid vendor specific naming.
- Use meaningful variable descriptions.
Sometimes even a properly named variable still needs additional clarification. A good variable description includes details about when and where a variable is set, which vendor is using the variable, and possible values to expect in the variable. Examples:
- Login status
authenticated, used for
eVar1in Adobe Analytics.
- Order subtotal does not include tax or shipping, exclude commas and currency symbols.
- Login status
- Avoid pluralized variable names.
Variables that contain multiple values, such as the product array variables, should use the singular form of the name. Examples:
- Prefix boolean variable names with
This allows you to quickly identify variables that contain a value of
- Creates a consistent naming convention.
- Easier for new users to understand what is available in your data layer and how each variable is used.
- Tealium Support is familiar with this convention.
- Additional effort to transition vendor-specific variables to vendor-neutral naming convention.
Use string values for all non-product variables. Boolean and numeric variables should be passed as strings.
For boolean values, use
0 instead of
false. This approach is more stable and reduces confusion about the expected values in these variables.
- Tag templates expect strings and arrays.
- Minimizes testing effort during and after implementation.
Set product variables (price, quantity, ID, etc.) as arrays. The Universal Tag (
utag.js) is designed to use arrays for all product variables. While it is possible to set product values in a comma-separated string, this approach is more prone to errors.
product_id : ["prodID1","prodID2","prodID3"]
product_id : "prodID1,prodID2,prodID3"
- Same format expected by vendor tag templates.
- Improves readability of the data layer.
All pages of your site should include a variable called
page_type. This is used to determine the type of page the user is viewing. The suggested values include, but are not limited to:
|Category / Product List||
|Cart / Basket||
|Checkout Flow (User Info, Billing Address, Shipping Address)||
|Order Confirmation / Thank You||
- Gives a clear understanding of what kind of page the user is viewing.
- Many vendor tags utilize a page type to function properly.
- Initial development effort to add
page_typevariable to the Universal Data Object.
Third-party data layer objects
You might already have a data layer object implemented on your site, such as the W3C Data Object or your own custom object. We recommend that these objects be converted to the UDO
utag_data format using one of the available data layer converters.
- Better compatibility with built-in functionality, such as load rules, data mappings, and Web Companion.
- Reduces support costs to investigate issues with your custom object.
- Additional effort to implement.
Thank you for your feedback!
This page was last updated: January 7, 2023