I am trying to implement the W3C standard for a data layer but have run into a snag. Looks like arrays are not allowed in the path for a JS object in a data element. For example, this only returns an empty string in a data element but returns the expected value in the console:
Yes, Arrays are not allowed in the path for a JS Object in a data element. For making it work Choose the Data Element Type as "Custom Script" instead of "JS Object" and return digitalData.user.profile.profileInfo.userName from the custom script.
Please let us know in case of any more questions or queries.
We have talked to the engineering team and they are saying that there is a particular way in which we can represent path as an array in a JS object type for Data Elements. Please see the following content for more details.
Complex JSON object containing Arrays
Complex JSON object using Array
In DTM it is different. If you want to create a data element to extract userName value from a complex Json object using Array then you will have to use-
Example of rule :
for this Path- digitalData.user.profile.profileInfo.userName
you have to use a path like this -
In DTM when you use a data element based on JS path then you will need to use the following if you want to extract a value from a JavaScrtipt array : arrayName.x where x is the index of the value in the array.