Last active
April 16, 2021 13:46
-
-
Save gabrielwalt/6860ba24852f6f6a9f1c53f36605a45c to your computer and use it in GitHub Desktop.
ACDL eventing, manually tracking the variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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/[email protected]/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"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have some
push
that setx
and others that sety
and you want to consolidate the state between those two, then thosepush
must share the same"test"
event that you can listen to. This will allow to get everything in order, and to track in your ownstate
variable what happened.