Need help in creating a DataElement

aaront37812270

27-11-2018

I'm trying to create a dataelement that will read an object called "transactionProds", and its properties. in my site code this is what i have:

var transactionProds = {

                  "sku": "SM-T280NZKAXAC",

                  "name": "Galaxy Tab A (7.0)",

                  "category": "",

                  "price": "199.99",

                  "quantity": "1",

                  "discount": "0.0"

              };

              digitalData.ecommerce.transactionProducts.transactionProds;

             

              var transactionProds = {

                  "sku": "SM-G955WZKAXAC",

                  "name": "Galaxy S8+",

                  "category": "",

                  "price": "959.99",

                  "quantity": "1",

                  "discount": "0.0"

              };

              digitalData.ecommerce.transactionProducts.push(transactionProds);

it could be a single product or multiple products. how do get the dataelement to read the multiple objects and its properties. I have tried this - where i used digitalData.ecommerce.transactionProducts in the path - but the result is: [object%20Object]

Edit Data Element

Accepted Solutions (0)

Answers (4)

Answers (4)

StewSchilling

MVP

11-12-2018

To rephrase your request... You have this:

Which from the console yields this:

You want a data element that will return your sku(s) and another that will return your quantity(s), etc.

The problem is really that DTM data elements can hold anything but the DTM UI (for Adobe Analytics and other tools) resolves data elements into strings (and will choke on complex data types that cannot be coerced into strings (thus [object%20Object]).

You CAN access individual array indexes in the Path field of a JS data element, so you could get at the 1st, 2nd, 3rd sku with three data elements using:

...but this is dumb (and probably not what you are looking for).

If you need to iterate through the items of transactionProducts you'll need to do it in custom JS.

What is your end goal?  Are you trying to get this data into Adobe Analytics?  Into Google Analytics? Into 3rd party tags? Other?

zaned72942122

28-11-2018

You're trying to push to an Object instead of an Array.

Your code should be in this order using an array of objects:

- Declare your array

var digitalData = {};

    digitalData.ecommerce = {};

    digitalData.ecommerce.transactionProds = [];

- Push to it.

var aProduct = {

    'sku':'12345',
    'name':'Product Name'

};

digitalData.ecommerce.transactionProds.push(aProduct);

Accessing all of the products and using them how you need them might require some custom code to do; it really depends on what you're trying to do with your data.

aaront37812270

29-11-2018

Thanks for the reply - the code that i mentioned above is automatically generated by our CMS, i should have made it clear. i pasted it there just for reference. what im trying to say is that how do i display the objects properties in my tag, for example my object is "trransactionProds, and its properties are "SKU, NAME...etc" i need to display the Sku in my rules tag.