Need help in creating a DataElement

Avatar

Avatar
Boost 1
Level 1
aaront37812270
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
aaront37812270
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
aaront37812270
Level 1

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 (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 3
Level 2
zaned72942122
Level 2

Likes

3 likes

Total Posts

5 posts

Correct reply

3 solutions
Top badges earned
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile

Avatar
Boost 3
Level 2
zaned72942122
Level 2

Likes

3 likes

Total Posts

5 posts

Correct reply

3 solutions
Top badges earned
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile
zaned72942122
Level 2

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.

Answers (3)

Answers (3)

Avatar

Avatar
Coach
MVP
StewSchilling
MVP

Likes

342 likes

Total Posts

279 posts

Correct reply

85 solutions
Top badges earned
Coach
Give Back 25
Springboard
Bedrock
Validate 1
View profile

Avatar
Coach
MVP
StewSchilling
MVP

Likes

342 likes

Total Posts

279 posts

Correct reply

85 solutions
Top badges earned
Coach
Give Back 25
Springboard
Bedrock
Validate 1
View profile
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?

Avatar

Avatar
Coach
Employee
Gigazelle
Employee

Likes

473 likes

Total Posts

1,947 posts

Correct reply

740 solutions
Top badges earned
Coach
Contributor 2
Validate 1
Ignite 80
Ignite 70
View profile

Avatar
Coach
Employee
Gigazelle
Employee

Likes

473 likes

Total Posts

1,947 posts

Correct reply

740 solutions
Top badges earned
Coach
Contributor 2
Validate 1
Ignite 80
Ignite 70
View profile
Gigazelle
Employee

04-12-2018

Try this maybe?

digitalData.ecommerce.transactionProducts.sku.toString();

Avatar

Avatar
Boost 1
Level 1
aaront37812270
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
aaront37812270
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
aaront37812270
Level 1

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.