saving an object or array in a data element in Adobe Dynamic Tag Manager | Community
Skip to main content
October 16, 2015
Solved

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

  • October 16, 2015
  • 3 replies
  • 2178 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Chasin


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

3 replies

Chasin
Adobe Employee
ChasinAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015


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
October 16, 2015

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.

Chasin
Adobe Employee
Adobe Employee
October 16, 2015

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.