Methods overview
When the Adobe Client Data Layer (ACDL) library loads, it adds the following methods and properties to the adobeDataLayer array:
addEventListener() added.version"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.