Methods overview

When the Adobe Client Data Layer (ACDL) library loads, it adds the following methods and properties to the adobeDataLayer array:

Method or property
Description
push()
Adds data, events, and functions to the data layer. Available before and after the library loads.
getState()
Returns a copy of the computed state, or of the value at a path.
addEventListener()
Calls a function when a named event or a built-in event is triggered.
removeEventListener()
Removes listeners that addEventListener() added.
version
A string that contains the version of the ACDL library, such as "3.0.1".

Call methods safely call-safely

If ACDL loads asynchronously, which is the recommended approach, your code can run before the library loads. At that point, adobeDataLayer is a plain array: push() exists, but getState(), addEventListener(), and removeEventListener() don’t.

To call these methods safely, push a function. ACDL runs it as soon as the library is ready and passes the data layer as its argument:

window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push(function(dl) {
  const title = dl.getState("page.title");
  dl.addEventListener("cart add", handleCartAdd);
});

Calling adobeDataLayer.getState() directly works only when you’re sure that ACDL has already loaded, such as in your browser’s developer console or in code that runs from an ACDL event listener.

Array methods array-methods

adobeDataLayer is still a JavaScript array. You can read it with methods that don’t change it, such as filter(), find(), and length. Don’t use methods that change the array, such as splice() or shift(). See Queue and history.

recommendation-more-help
experience-platform-help-collection