DTM - How to use an array for a Data Element?

Avatar

Avatar
Validate 1
Level 1
tyler_lamb
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
tyler_lamb
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
tyler_lamb
Level 1

15-10-2015

I'm trying to figure out how to utilize an array in a Data Element using DTM.  Let's say I have the following:

var datalayer = { products: [ { sku:'Product 1', quantity:7, price:9.12 },{ sku:'Product 2', quantity:5, price:4.78 } ] }

Essentially I want to setup a Data Element for the products, and then use this to set the products variable for Site Catalyst.  What is the best way to do this?

Thanks for your time!

Tyler

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Seeker
Employee
Jeff__Chasin
Employee

Likes

12 likes

Total Posts

36 posts

Correct reply

12 solutions
Top badges earned
Seeker
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Seeker
Employee
Jeff__Chasin
Employee

Likes

12 likes

Total Posts

36 posts

Correct reply

12 solutions
Top badges earned
Seeker
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile
Jeff__Chasin
Employee

15-10-2015

If that datalayer object exists in your page, you can just point the DTM Data Element at it. When  you set up your Data Element, you can use JS Object as the Type, and in the Path, you just type datalayer.products

You don't have to use a Data Element here, but you can. When you set your products variable, you can just reference datalayer.products[0].sku or whatever.

Answers (3)

Answers (3)

Avatar

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile
joshd7227840
MVP

15-10-2015

DTM does not have a built-in field for populating s.products for Adobe Analytics.  

To set s.products, you will need to set it in Adobe AnalyticsCustom Page Code section of your rule. 

Here is some example code for this, based on the datalayer structure you provided. The assumption is that you put the products array into a data element called products

var products=_satellite.getVar('products'); s.products=[]; for (var p=0,l=products.length;p<l;p++) { var prod=[]; prod.push(''); prod.push(products[p].sku||''); prod.push(products[p].quantity||''); prod.push(products[p].price||''); s.products.push(prod.join(';')); } s.products=s.products.join();

 

Note that if this is supposed to be an s.tl call, you will also need to set (or append to) s.linkTrackVars.

Avatar

Avatar
Validate 1
Employee
Ben_Bytheway
Employee

Likes

40 likes

Total Posts

62 posts

Correct reply

22 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Employee
Ben_Bytheway
Employee

Likes

40 likes

Total Posts

62 posts

Correct reply

22 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Ben_Bytheway
Employee

15-10-2015

As far as I can tell, right now the only way to set the products variable is through code.  There is no interface that allows you to set s.products for DTM UI.

If your code above were run on the global scope, you could set your products variables by simply assigning the s.products variable to a concatenation of pieces from your datalayer object.  You would do this in the same way as @jeffchasin mentioned above.  

Avatar

Avatar
Validate 1
Level 1
tyler_lamb
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
tyler_lamb
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
tyler_lamb
Level 1

15-10-2015

I have set up datalayer.products as a data element.  (Lets say I named that element "Products")

I guess what is the best way to set the products variable?  Would I have to code it on the site itself, or can I configure the setting of s.products in DTM somehow now the array is saved in a data element?