-
Notifications
You must be signed in to change notification settings - Fork 27
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
Capability to reset the data layer #45
Comments
Given that we want to allow instantiating a new data layer (see #44), we could also use that to reset the data layer. Here's an example of how that could work for an SPA that wants to reset the data layer each time the visitor gets routed to a different URL: window.addEventListener("popstate", function (event) {
window.adobeDataLayer = new AdobeDataLayer();
// Register again your event listeners here.
}); This has been documented here: |
When a view change happens in SPA, the Data Layer does not always change in its entirety, So it will be good to give flexibility for the developers to decide what should be reset and what should be retained when a reset is called on the Data Layer. For instance, when a user authenticates, the User object of the data layer will be populated. Further view change on the same session can retain this User object. Resetting the Data Layer completely will require the developers to pull user data from backend on every view change. it will be great if developers can call reset with a an object and array list of events to retain. Example of how the API could potentially look: // Example for clearing/resetting everything
adobeDataLayer.reset({}, []); // retain user and navigation component object and reset all other data.
// retain "click" and "view-change" event handlers and remove all other event handlers.
adobeDataLayer.reset({
"component" : {
"navigation" : adobeDataLayer.getState("component.navigation")
},
"user": adobeDataLayer.getState("user")
},
["click", "view-change"]
); |
We could introduce a
WDYT? @bennet-roy @gabrielwalt |
Sounds good. Just to add more flexibility, Can we add a flag which can tell whether to keep or remove whatever is in the Array? //For removing
const options = {
paths: ["page", "component.carousel.carousel1"],
events: ["click"],
action : remove
};
dataLayer.reset(keepOptions);
//For keeping
const options = {
paths: ["page", "component.carousel.carousel1"],
events: ["click"],
action : keep
};
dataLayer.reset(options);
|
A proof of concept is available at: It works as follows: // For keeping
const options = {
keep: {
paths: ["component.carousel.carousel4"],
events: ["click"],
history: true // will keep the data layer items history
}
};
adobeDataLayer.reset(options);
// For removing
const options = {
remove: {
paths: ["component.carousel.carousel4"],
events: ["click"],
history: true // will remove the data layer items history
}
};
adobeDataLayer.reset(options); |
How's the status for adding this functionality? |
Is there any update on this issue? It would be very useful. |
For web applications like SPA, it should be possible to simulate a reset of the data layer as when a new page is loaded. This is especially important in cases the Data Layer holds a lot of information and triggers many events because the array can then quickly become massive if a visitor actively browses around for a few minutes or more.
For example:
adobeDataLayer.reset();
A more detailed example:
The text was updated successfully, but these errors were encountered: