Leiste mit Community-Erfolgen erweitern.

Join us on September 25th for a must-attend webinar featuring Adobe Experience Maker winner Anish Raul. Discover how leading enterprises are adopting AI into their workflows securely, responsibly, and at scale.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

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

Avatar

Level 2

 Hello all,

I'm working with the W3 dataLayer and want to trigger a rule when a certain product is on the page, but I don't know how I can create a data-element that is based on a array. So for example I have the following dataLayer and I want to trigger a rule when the product name contains laptop. How can I do this?

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

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

Hi Guidov, 

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.

By default in JavaScript if you want to extract userName value then you would use simple javascript syntax.
In DTM it is different. If you want to create a data element to extract productName value from a complex Json object using Array then you will have to use-
Example of rule : 
 for this Path- digitalData.listing[0].productInfo.productName
you have to use a path like this - 
digitalData.listing.0.productInfo.productName
 
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.
 
Thanks & Regards
Parit Mittal

Lösung in ursprünglichem Beitrag anzeigen

1 Antwort

Avatar

Korrekte Antwort von
Level 10

Hi Guidov, 

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.

By default in JavaScript if you want to extract userName value then you would use simple javascript syntax.
In DTM it is different. If you want to create a data element to extract productName value from a complex Json object using Array then you will have to use-
Example of rule : 
 for this Path- digitalData.listing[0].productInfo.productName
you have to use a path like this - 
digitalData.listing.0.productInfo.productName
 
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.
 
Thanks & Regards
Parit Mittal