Accessing the Data Layer With the get() Method

Sometimes a data layer and its objects can’t be called in the standard way, which complicates using the data layer in a user journey. In most cases, if you know the name of the data layer, you simply access a variable of the data layer with this syntax: dataLayerName.object. For example, at the data layer is called utag_data and the variable for the name of the product is called product_name. An application that needs access this value can call it using “dot” notation: utag_data.product_name.  

But when a data layer variable can’t be called in this way, you may need to get the data layer before trying to access any of its data. Use this syntax to expose a data layer: myDataLayerName.get().variableName. An example of this is at, where the data layer is called by entering DataLayer.get() in the JavaScript console. If you use this get() method for your data layers, enter myDataLayerName.get in the Data Layer Object or Function field when you set up a Domain (be sure to omit the parentheses). Any calls to the data layer must use the syntax: myDataLayerName.get().objectInMyDataLayer. For example, use this to get the name of the page from the Toyota site: DataLayer.get().lastEvent.pageName.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.