-
Notifications
You must be signed in to change notification settings - Fork 26
Description
the data layer script does declare the adobeDataLayer array and therefore also doesn't initialize it if it hasn't been declared already prior to the script loading.
Expected Behaviour
It is expected that scripts behave the same way, regardless whether the data layer script is loaded before or after the adobeDataLayer variable has been declared.
Actual Behaviour
The adobeDataLayer array must be declared prior to the Adobe Client Data Layer script being loaded, or the data layer doesn't get initialized and won't be useable on the page.
Reproduce Scenario
Following HTML doesn't fires the test event as expected:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Data Layer</title>
<script src="https://unpkg.com/@adobe/adobe-client-data-layer@1.1.0/dist/adobe-client-data-layer.min.js"></script>
<script>
window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push({"event": "test", "eventInfo": "hello world"});
window.adobeDataLayer.push(function(dl) {
dl.addEventListener("test", function(e) { console.log(e); });
});
</script>
</head>
<body>
<h1>Data Layer</h1>
</body>
</html>But adding async defer attributes to the first script element, or interchanging the two script elements will make it work.
It would be expected that the data layer script does declare the adobeDataLayer array if it hasn't been declared already.