Created
April 16, 2021 13:41
-
-
Save gabrielwalt/4d3f2a48fb04f6582d6f693f690a18d0 to your computer and use it in GitHub Desktop.
ACDL eventing, manually tracking the variables with generic event
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", | |
x: 1 | |
}); | |
adobeDataLayer.push({ | |
event: "test-y", | |
y: "a" | |
}); | |
adobeDataLayer.push({ | |
event: "test-x", | |
x: 2 | |
}); | |
adobeDataLayer.push({ | |
event: "test-y", | |
y: "b" | |
}); | |
adobeDataLayer.push(function (dl) { | |
var state = {}; | |
dl.addEventListener("adobeDataLayer:event", function(e) { | |
if (e.event === "test-x" || e.event === "test-y") { | |
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", x: 1} | |
// {event: "test-y", x: 1, y: "a"} | |
// {event: "test-x", x: 2, y: "a"} | |
// {event: "test-y", x: 2, y: "b"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the events that push
x
andy
are not the same, but you still want to consolidate the state between those two, then you can use the genericadobeDataLayer:event
event, and filter inside the callbacks to the desired events.