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

Questo prodotto è concesso in licenza in base alla licenza di Attribuzione-Non commerciale-Condividi allo stesso modo 3.0 Unported di Creative Commons.  I post su Twitter™ e Facebook non sono coperti dai termini di Creative Commons.

Note legali   |   Informativa sulla privacy online