Skip to content

Instantly share code, notes, and snippets.

@gabrielwalt
Last active April 16, 2021 13:46
Show Gist options
  • Save gabrielwalt/6860ba24852f6f6a9f1c53f36605a45c to your computer and use it in GitHub Desktop.
Save gabrielwalt/6860ba24852f6f6a9f1c53f36605a45c to your computer and use it in GitHub Desktop.
ACDL eventing, manually tracking the variables
// In a browswer window with URL about:blank
// Open the JS console and paste this code
window.adobeDataLayer = [];
adobeDataLayer.push({
event: "test",
x: 1
});
adobeDataLayer.push({
event: "test",
y: "a"
});
adobeDataLayer.push({
event: "test",
x: 2
});
adobeDataLayer.push({
event: "test",
y: "b"
});
adobeDataLayer.push(function (dl) {
var state = {};
dl.addEventListener("test", function(e) {
state = Object.assign(state, e);
console.log(state);
});
});
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:
// {event: "test", x: 1}
// {event: "test", x: 1, y: "a"}
// {event: "test", x: 2, y: "a"}
// {event: "test", x: 2, y: "b"}
@gabrielwalt
Copy link
Author

gabrielwalt commented Apr 16, 2021

If you have some push that set x and others that set y and you want to consolidate the state between those two, then those push must share the same "test" event that you can listen to. This will allow to get everything in order, and to track in your own state variable what happened.

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