DTM and Data Element based on JS ARRAY and JSON ARRAY - alcazes/Adobe-Analytics-from-A-To-Z GitHub Wiki

Simple JavaScript Array

Simple JavaScript Array

var testArray = ["value1","value2","value3"];

By default in JavaScript if you want to extract first value then you would use

testArray[0]

In DTM it is different. If you want to create a data element to extract first value then you will have to use:

testArray.0

Example of rule:

Example1

Outcome in browser console:

Example1 outcome

Complex JSON object containing Arrays

Complex JSON object using Array

var digitalData = {
            "user" : [{
                "profile" : [{
                    "profileInfo" : {
                        "userName" : "Alexis"
                    }
                }]
            }]
        }

By default in JavaScript if you want to extract userName value then you would use

digitalData.user[0].profile[0].profileInfo.userName

In DTM it is different. If you want to create a data element to extract userName value then you will have to use

digitalData.user.0.profile.0.profileInfo.userName

Example of rule:

Example2

Outcome in browser console:

Example2 outcome

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.