Skip to content

Instantly share code, notes, and snippets.

@gabrielwalt
Last active April 16, 2021 13:45
Show Gist options
  • Save gabrielwalt/c64895896334cb5314adc9e3d013b03e to your computer and use it in GitHub Desktop.
Save gabrielwalt/c64895896334cb5314adc9e3d013b03e to your computer and use it in GitHub Desktop.
ACDL eventing with getState
// In a browswer window with URL about:blank
// Open the JS console and paste this code
window.adobeDataLayer = [];
adobeDataLayer.push(function (dl) {
dl.addEventListener("test", function() {
console.log(dl.getState());
});
});
adobeDataLayer.push({
x: 1
});
adobeDataLayer.push({
event: "test",
y: "a"
});
adobeDataLayer.push({
x: 2
});
adobeDataLayer.push({
event: "test",
y: "b"
});
var scriptElement = document.createElement('script');
scriptElement.src = "https://unpkg.com/@adobe/adobe-client-data-layer@2.0.1/dist/adobe-client-data-layer.js";
document.body.append(scriptElement);
// Console output will be:
// {x: 1, y: "a"}
// {x: 2, y: "b"}
@gabrielwalt
Copy link
Author

gabrielwalt commented Apr 16, 2021

See how getState inside the event handler returns the state correctly, as it was at the moment of the event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment