Pass an Event Value from an Array into a Data Element
Hi,
I am trying to grab a string from a digitalData datalayer event and pass that to a a JS/jQuery "Custom Code" Data Element. I can get the right value to return in Console using the below code, but it passes nothing (likely "undefined") when implementing the same thing in the Custom Code Data Element.
if (digitalData.event.length) {
digitalData.event.forEach(function(e) {
if (e.eventName === "Product Search") {
console.log(e.eventDetails.search_query)
}});
} else {
/// do nothing
}
For additional background, the array is digitalData.event and each item in the array has a different number. What I am looking to capture/pass to the Data Element could related to any number in that array (digitalData.event.[n]). Within that item in the array, I am looking to identify that it has eventName = "Product Search" and then pass the string value of its eventDetails.search_query. Additionally, I do want it to pass nothing/unspecified if nothing in the array has an eventName = "Product Search".
In looking at documentation, I notice a lot of people pointing to the Data Layer Manager extension as created by Search Discovery. However, the sensitive nature of the site in question's industry often precludes use of 3rd-party providers wherein there is risk for data leakage or privacy concerns, so would prefer not to have to use that. If there is a first party Adobe extension, that might be acceptable to use, though seems like it should be achievable without such a thing (I could be wrong).
Any and all help would be greatly appreciated, thank you!!