Hi Community,
I am having difficulty populating specific Data Elements that are meant to be grabbing values from an array in an AppEventData datalayer. When testing in Console, I can get the right value to populate there, but when pasting the same syntax into a "Javascript Variable" Data Element, it does not pass anything.
For example, this works in Console but not in a "Javascript Variable" Data Element: "AppEventData[1].purchase.price.purchaseAmount"
I have tried the following to help resolve, but to no avail:
Note: The website/company in question is very sensitive about any potential (founded or unfounded) for "data privacy leakage", so would prefer to avoid using any third-party extensions (e.g. the Search Discovery ones).
It seems weird that it works correctly in console, but not within the Data Element, especially since the non-array stuff populates correctly within the same tag. Is there something I am missing in regards to using "Javascript Variable"-informed Data Elements when trying to get values out of arrays?
Thank you, appreciate any assistance that may spring to mind!!
Solved! Go to Solution.
Yeah, I have noticed the same thing... I just ended up using a custom code Data Element to pull the value, which does work.
So instead of:
Use Custom Code:
This is also how I process arrays of data... I pull them into a custom code data element, and use JS to process the items into a delimited list that I then "return" as my Data Element value, or I can add logic to the code as well.....
Yeah, I have noticed the same thing... I just ended up using a custom code Data Element to pull the value, which does work.
So instead of:
Use Custom Code:
This is also how I process arrays of data... I pull them into a custom code data element, and use JS to process the items into a delimited list that I then "return" as my Data Element value, or I can add logic to the code as well.....
Instead of using square brackets, use dot-notation to access the array's elements, i.e.
AppEventData.1.purchase.price.purchaseAmount
Both great answers and both seemingly work, thank you!! @Jennifer_Dungan got the "correct reply" for being first, but @yuhuisg 's solution also seems to work.
Generally there are multiple ways to solve any problem
With my way, you can also do extra logic / processing on the array if needed... but if you always need the "first" item, then both work