Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

saving an object or array in a data element in Adobe Dynamic Tag Manager

larryarmstrong_
Level 1
Level 1

I tried to save a javascript array or javascript object in a data element in DTM, but it does not work. It just translates it to an encoded string.

Is there a way to make this work?

If not, how am I supposed to populate data of a dynamic size, for example an array of each item in the cart, with individual attributes (name, price, quantity), for each one?

I have a PIWIK script that is expecting this on the confirmation page.

I can collect and save this data to a js object on my page, but I am not able to successfully use this data in DTM.

1 Accepted Solution
Jeff__Chasin
Correct answer by
Employee
Employee


Ok, I thought you were creating the object in the Data Element.

If you have an array like var items = ['foo', 'bar', {key: 'value'}] either in a data element or in the DOM (in the page), or in a custom script section in DTM, you could reference elements of the array in a few ways:   

items[2].key // returns 'value' from the above array _satellite.data.customVars.object_test[2].key  // returns 'value' from a data element called object_test that contains the array _satellite.data.customVars.object_test[0]  // returns 'foo' %window._satellite.data.customVars.object_test[2].key%  // returns 'value' from the data element, in the user interface fields

View solution in original post

3 Replies
Jeff__Chasin
Employee
Employee

Are you returning the object as the last line of the script for the data element?

var myObject = { key = "value", foo = "bar" }; return myObject;

With custom script data elements or conditions, the return statement is required.

larryarmstrong_
Level 1
Level 1

that does not work.

i tried this as my data element custom script:

return window.piwikVars.items;

 

then in my script tag i am adding:

var myArray = %piwikItems%;

 

but it is not seeing as an array: it is giving an error like this:

[img]Screenshot 2014-10-09 16.42.45.png[/img]

 

i can see the populated array in my DOM inspector so I know that the variable exists and is populated correctly.

Jeff__Chasin
Correct answer by
Employee
Employee


Ok, I thought you were creating the object in the Data Element.

If you have an array like var items = ['foo', 'bar', {key: 'value'}] either in a data element or in the DOM (in the page), or in a custom script section in DTM, you could reference elements of the array in a few ways:   

items[2].key // returns 'value' from the above array _satellite.data.customVars.object_test[2].key  // returns 'value' from a data element called object_test that contains the array _satellite.data.customVars.object_test[0]  // returns 'foo' %window._satellite.data.customVars.object_test[2].key%  // returns 'value' from the data element, in the user interface fields

View solution in original post