-1

I am new to this site and to developing with jQuery so I am sorry if this is a newbie question. I have been tasked with adding an array of products that are on the page to a google dynamic retargeting tag. I have my array filled with the correct data but I cant seem to add it to the tag as a variable. I am getting a parsing error saying "Expected ':'" within visual studio 2013 here is the code:

 var productsString = JSON.stringify(products, null, 4);

    var google_tag_params = {  

        productsString    /* ERROR HERE */
    };
    /* <![CDATA[ */
    var google_conversion_id = 1030976867;
    var google_custom_params = window.google_tag_params;
    var google_remarketing_only = true;

Thank you for your help.

chromeOne7
  • 33
  • 2
  • 8
  • You're missing your parameter name. – ElGavilan Nov 07 '14 at 14:58
  • They are inside of my array productsString. So do you think I will have to iterate thru the array and spit them out in a loop? – chromeOne7 Nov 07 '14 at 15:41
  • Elements in associative array have to be declared as `keyname: 'value'`. See http://www.i-programmer.info/programming/javascript/1441-javascript-data-structures-the-associative-array.html – ElGavilan Nov 07 '14 at 15:49

1 Answers1

0

Elements in associative array have to be declared as keyname: 'value'.

So your code needs to look like this:

var google_tag_params = {  

    keyname: 'value'
};

In your case, since productsString contains an array of your elements, you will need to convert it to an associative array. See this question for information on how to do that.

http://www.i-programmer.info/programming/javascript/1441-javascript-data-structures-the-associative-array.html

Community
  • 1
  • 1
ElGavilan
  • 6,610
  • 16
  • 27
  • 36