Is seems that the ACDL script is adding events to the adobeDataLayer array only after the callbacks of the events have completed. This leads to an odd ordering of the event entries in the adobeDataLayer array.
Consider the following script:
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/@adobe/adobe-client-data-layer@2.0.1/dist/adobe-client-data-layer.min.js" async defer></script>
<script>
window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push(function (dl) {
dl.addEventListener("one", function () {
logItemEvent("2: ", 0);
logItemEvent("2: ", 1);
dl.push({ event: "two" });
logItemEvent("3: ", 0);
logItemEvent("3: ", 1);
});
logItemEvent("1: ", 0);
logItemEvent("1: ", 1);
dl.push({ event: "one" });
logItemEvent("4: ", 0);
logItemEvent("4: ", 1);
function logItemEvent(prependText, item) {
if (dl[item] && dl[item].event) {
return console.log(prependText+"adobeDataLayer["+item+"].event = "+dl[item].event);
}
return console.log(prependText+"adobeDataLayer["+item+"] = "+dl[item]);
}
});
</script>
</head>
<body></body>
</html>
The resulting log output is:
1: adobeDataLayer[0] = undefined
1: adobeDataLayer[1] = undefined
2: adobeDataLayer[0] = undefined
2: adobeDataLayer[1] = undefined
3: adobeDataLayer[0].event = two
3: adobeDataLayer[1] = undefined
4: adobeDataLayer[0].event = two
4: adobeDataLayer[1].event = one
But the expected output would have been:
1: adobeDataLayer[0] = undefined
1: adobeDataLayer[1] = undefined
2: adobeDataLayer[0] = one
2: adobeDataLayer[1] = undefined
3: adobeDataLayer[0].event = one
3: adobeDataLayer[1] = two
3: adobeDataLayer[0].event = one
3: adobeDataLayer[1] = two
It would be expected that the ACDL appends the event object to the adobeDataLayer array prior to calling the callbacks that have been registered to that event, and not after. Because otherwise, notice how the events one and two end up in the reverse order.
Is seems that the ACDL script is adding events to the
adobeDataLayerarray only after the callbacks of the events have completed. This leads to an odd ordering of the event entries in theadobeDataLayerarray.Consider the following script:
The resulting log output is:
But the expected output would have been:
It would be expected that the ACDL appends the event object to the
adobeDataLayerarray prior to calling the callbacks that have been registered to that event, and not after. Because otherwise, notice how the eventsoneandtwoend up in the reverse order.