Parit Mittal
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:
digitalData.user[0].profile[0].profileInfo.userName
Anything I should be doing differently?
Solved! Go to Solution.
Hi Christy ,
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[0].profile[0].profileInfo.userName from the custom script.
Please let us know in case of any more questions or queries.
Thanks & Regards
Parit Mittal
Views
Replies
Total Likes
Hi Christy ,
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[0].profile[0].profileInfo.userName from the custom script.
Please let us know in case of any more questions or queries.
Thanks & Regards
Parit Mittal
Views
Replies
Total Likes
Thank you Parit. Any idea if engineering is working to allow arrays for a JS object in a future release?
Views
Replies
Total Likes
Hi Christy,
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.
Example of rule :
for this Path- digitalData.user[0].profile[0].profileInfo.userName
you have to use a path like this -
digitalData.user.0.profile.0.profileInfo.userName
So to be able to extract value from an array in JavaScript you would use arrayName[x] where x is the index of the value in the array.
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.
Parit Mittal
Hi Parit,
Thank you for this response, it is exactly what I was looking for. Much more readable than having to use custom code for just pulling a value out of the data layer.
Thanks!
Christy
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies