I'm having difficulty retrieving the value for the last event that includes "SearchResults" in the scenario outlined below: Here is a schema of my datalayer where I am looking to gather information.
Currently, I have managed to write the following code to determine if a SearchResult event exists:
//Check if an existing event contains Search Results
if (digitalData.event.filter(e => e.componentID === 'SearchResults').length > 0) {
// If there are any that exist, I want to retrieve the pageIndex value of the last one generated
console.log("exist");
} else {
// If it doesn't exist, return 1
return 1;
};
Now, I am facing challenges in figuring out how to specifically select the most recent event generated and fetch the value stored in "digitalData.event.attributes.pageIndex".
Does anyone have a solution for this issue?
Thank you,