How to create a data-element based on a JSON object array?

While working with the W3 dataLayer there have been many instances where a DTM user wants to create a data-element that is based on a array. Example- you have the following dataLayer and want to create a data element to store product name of first product in the listing 

var digitalData = {
    "listing":
        [
        {
            "productInfo":
            {
            "productName": "laptop", 
            "productId": "19381652"
            }
            
        },
        {
            "productInfo":
            {
            "productName": "tv", 
            "productId": "19381654"
            }
            
        }
        ]
    }

Hence there is a particular way in which we can represent path as an array in a JS object type for Data Elements. 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 JavaScript array : arrayName.x where x is the index of the value in the array.

Considering the above data layer, if you want to create a data element to extract productName value from a complex Json object using Array  you have to use a path like this - digitalData.listing.0.productInfo.productName

 Adobe

Gaukite pagalbą greičiau ir lengviau

Naujas vartotojas?

Adobe MAX 2024

Adobe MAX
Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX

Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX 2024

Adobe MAX
Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX

Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu