Skip to content

Instantly share code, notes, and snippets.

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

If what you are interested in is tracking all changes done to the variable x, then you can define an event listener to track any changes done to that with the adobeDataLayer:change event that you can limit to the path x.

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