Create a data layer
A data layer is a JavaScript structure on your site that exposes the data your Analytics implementation collects, such as page names, product details, and order IDs. Your site code writes to the data layer, and your implementation reads from it to set Analytics variables. Because your implementation doesn’t depend on the page’s HTML, you can redesign your site without breaking data collection.
Prerequisites
Create a solution design document: It is important for your organization to align on tracking requirements. Make sure that you are prepared with a solution design document before approaching development teams in your organization. The data that your solution design requires determines what your data layer contains.
Choose a data layer specification specifications
Adobe recommends the Adobe Client Data Layer (ACDL) for new or restructured implementations. ACDL is an open-source JavaScript library that gives your site a standard way to push data and events to a global adobeDataLayer array. Tags, the Web SDK, and AppMeasurement can all read from it, and Adobe Experience Manager Core Components can populate it automatically.
Your organization is free to use other specifications, such as the Customer Experience Digital Data Layer (CEDDL), which stores data in a global digitalData object, or a custom specification. The most important thing is that your organization aligns on one specification that meets its needs.
The following table compares ACDL with object-based data layers such as CEDDL:
adobeDataLayer)digitalData)adobeDataLayer.push({ page: { name: "Home" } })digitalData.page.pageInfo.pageName = "Home"adobeDataLayer.getState("page.name"), or a Data layer computed state data element from the Adobe Client Data Layer tag extensiondigitalData.page.pageInfo.pageName, or a JavaScript Variable data element from the Core tag extension{ event: "page view" }, and your implementation listens for it. Listeners also run for events that were pushed before they were added.Example data layer example
ACDL doesn’t require a specific data structure. Design the structure around your solution design document, and document it for everyone who writes to the data layer or reads from it. The examples in this guide use the following structure.
When a page loads, site code pushes the page’s data and a page view event:
window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push({
event: "page view",
page: {
name: "Home",
section: "Products",
url: "https://example.com/products",
referrer: "https://example.com/"
}
});
When a visitor completes a purchase, site code pushes the order details and a purchase event:
window.adobeDataLayer.push({
event: "purchase",
transaction: { id: "ABC123" },
products: [
{ name: "Example product", category: "Example category", quantity: 1, price: 25 }
]
});
ACDL merges every push into a single object called the computed state, which your implementation reads. Event objects tell your implementation when to read it. See Data and the computed state and Events.
Workflow workflow
Implementing Adobe Analytics using a data layer typically follows these steps:
- Work with your site development team to implement a data layer: Your site development team is primarily responsible for making sure that the data layer contains correct values. Review this page with your site development team to make sure expectations are aligned between teams. See Install the Adobe Client Data Layer.
- Validate your data layer using a browser console: Open your browser’s developer console, which you can do in most browsers with the
F12key. RunadobeDataLayer.getState()to see the computed state, oradobeDataLayer.getState("page.name")to see a single value. See Verify the installation. - Connect the data layer to Adobe Analytics: This step varies based on your organization’s implementation method. See Connect the data layer to Adobe Analytics.
Connect the data layer to Adobe Analytics connect
The following table shows how each implementation method reads from the Adobe Client Data Layer:
data object with the Web SDK Update variable action, then send them with the Send event action.addEventListener(), and set XDM or data fields from the data layer when you call sendEvent.getState() after ACDL loads, then call s.t().Read the data layer with AppMeasurement appmeasurement
ACDL adds its getState() method to the adobeDataLayer array when the library loads. To make sure that the library has loaded and that the computed state includes the latest data, read values inside an event listener:
window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push(function(dl) {
dl.addEventListener("page view", function(event) {
s.pageName = dl.getState("page.name");
s.channel = dl.getState("page.section");
s.t();
});
});
The listener runs once for each page view event, including events that were pushed before the listener was added. The variable pages in this guide, such as pageName, show how to read individual values with getState(). Use those examples inside a listener like this one, or in the custom code editor of an Analytics extension rule that a Data layer push event triggers.
If your implementation sends more than one hit per page, such as in a single-page application, use clearVars() so that values from one hit don’t persist to the next.
Next steps
- Map data layer objects to data elements: Use your site’s data layer in Adobe Experience Platform tags.
- Adobe Client Data Layer documentation: Learn about every ACDL method, event, and best practice.