Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the full state on specific events #120

Open
gabrielwalt opened this issue Apr 19, 2021 · 1 comment
Open

Pass the full state on specific events #120

gabrielwalt opened this issue Apr 19, 2021 · 1 comment
Labels
enhancement New feature, or improvement to an existing feature.

Comments

@gabrielwalt
Copy link
Member

gabrielwalt commented Apr 19, 2021

As discussed with Benedikt Wedenik, for events that depend on data in the state that isn't provided by the event payload, when the event listener is registered late, it is impossible to recover how exactly the state was at the moment of the event.

In following example, see how there's no easy way for the "test" event listener to know that at the moment of the event x was equal to 1:

window.adobeDataLayer = window.adobeDataLayer || [];
adobeDataLayer.push({
    x: 1
});
adobeDataLayer.push({
    event: "test",
    y: 1
});
adobeDataLayer.push({
    x: 2
});
adobeDataLayer.push(function () {
    this.addEventListener("test", function(event) {
        console.log(this.getState());
    });
});
// Console output will be: {x: 2, y: 1}

If the event listener could have been registered before the other push, then this.getState() would have returned {x: 1, y: 1}, but this is often not possible as the event listeners get registered asynchronously, via Adobe Launch for example.

It would be nice if events that get registered late had a chance to access the full state as it was at the moment of the event, like by passing it as a parameter to the event:

adobeDataLayer.push(function () {
    this.addEventListener("test", function(event, state) {
        console.log(state);
    });
});
// Console output would then be: {x: 1, y: 1}

Or, if that's too much of a performance concern, then we should have a way to optionally request the full event for specific events:

adobeDataLayer.push({
    x: 1
});
adobeDataLayer.push({
    event: "test",
    y: 1,
    "adobeDataLayer:fullState": true
});
adobeDataLayer.push({
    x: 2
});
adobeDataLayer.push(function () {
    this.addEventListener("test", function(event, state) {
        console.log(state);
    });
});
// Console output will be: {x: 1, y: 1}
@gabrielwalt gabrielwalt added the enhancement New feature, or improvement to an existing feature. label Apr 19, 2021
@B3n3
Copy link

B3n3 commented Apr 19, 2021

Thanks @gabrielwalt, looking forward to seeing this feature in ACDL :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or improvement to an existing feature.
Projects
None yet
Development

No branches or pull requests

2 participants