title: Google Analytics code line break for _gaq.push(['_addTrans'
body: <p>Trying to get GA set up with our ecommerce store and running into an issue where the actual product items aren't publishing at all to GA. The total price is working fine, but none of the item data comes through.</p>
  
  <p>Using the Google Analytics debugger in Chrome, it seems as though this is happening because the values returned by the variables are on a separate line. When it is on a new line, Google reads it as having no value, at least that what it seems like.</p>
  
  <p>I've attached a screen of the debugger window to show the line breaks.</p>
  
  <p><img src="https://i.stack.imgur.com/i06GJ.png" alt="enter image description here"></p>
  
  <p>Before you take a look at the code, please note that in order to get the values and products and pricing, I have to traverse a table on the ecommerce thank you page because the ecommerce system we use doesn't have any API's...</p>
  
  <p>Here's the code with the table that was exported in a test order.</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  var purchaseTotal;
  var orderID = "[[S120:cart:orderId]]";
  var productQty = new Array(); //quantity of product
  var productName = new Array(); //name of product
  var productValue = new Array(); //price of product
  var productRows;
  var a = 0; //used to assign array values
  
  var _gaq = _gaq || []; //start _gaq to use globaly
  
  $(function(){
  
      function getQuerystring(key, default_){
        if (default_==null) default_=""; 
        key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regex = new RegExp("[\\?&amp;]"+key+"=([^&amp;#]*)");
        var qs = regex.exec(window.location.href);
        if(qs == null)
          return default_;
        else
          return qs[1];
      }
  
      var isThankyou = getQuerystring('CONFIRMATION');
  
      if(getQuerystring('CONFIRMATION') == 'true'){
  
  
      purchaseTotal = $("table.ShoppingCart tr:last-child").children("td:last-child").text();
      purchaseTotal = purchaseTotal.replace('$',''); //removes dollar sign from text for GA use
      purchaseTotal = purchaseTotal.replace(/\s+/g,""); //removes all extra spaces
      console.log("Total: "+ purchaseTotal);
  
      var rows = $("table.ShoppingCart tr").length;
      console.log("Rows: " + rows);
  
      //start going through the rows
      for(var i = 0; i &lt;= rows; i++){
  
  
          var cells = $("table.ShoppingCart tr").eq(i).children("td").length;
          var cell = $("table.ShoppingCart tr").eq(i).children("td");
          //if there 3 cells we're in business, it's a product
          if(cells == 3){
              //for every row, go through the cells if the length of cells in that row are 3
              for(var k = 0; k &lt; cells; k++){
                  if(k == 0){
                      //this is the quantity column, let's see how much was ordered
                      productQty[a] = $(cell).eq(k).text();
                      productQty[a] = productQty[a].replace(/\s+/g," ");
                      console.log("QTY: "+ productQty[a]);
                  }
                  if(k == 1){
                      //this is the product name column, what's the name?
                      productName[a] = $(cell).eq(k).text();
                      productName[a] = productName[a].replace(/\s+/g," ");
                      console.log("Name: "+ productName[a]);
                  }
                  if(k == 2){
                      //this is the price 
                      productValue[a] = $(cell).eq(k).text();
                      productValue[a] = productValue[a].replace("$","");
                      productValue[a] = productValue[a].replace(/\s+/g," ");
                      console.log("Value: "+ productValue[a]);
                      a++;
                  }
              }
          }
          //console.log("END i loop: "+ i);
      }
  
      productRows = productQty.length;
  
      ecommerceGACode(); // launch eccomerce GA code
  
    }//endif
    else{
        noEcommerceGA();
  
    }//end else
  
  });
  
  function ecommerceGACode(){
          //Google Analytics Code
      console.log("ThankYouPage GA launched");
      _gaq.push(['_setAccount', 'UA-2167264-1']);
      _gaq.push(['_setDomainName', '.convio.net']);
      _gaq.push(['_setSiteSpeedSampleRate', 5]);
          if (CONVIO.referrer.length != 0) {
              _gaq.push(['_setReferrerOverride',CONVIO.referrer]);      
          }
      _gaq.push(['_trackPageview']);
  
      _gaq.push(['_addTrans',
        orderID,           // order ID - required
        'ECommerce Store',  // affiliation or store name
        purchaseTotal,          // total - required
        '',           // tax
        '',              // shipping
        '',       // city
        '',     // state or province
        ''             // country
      ]);
  
    //loop through our array's and insert the values!
    for(var i = 0; i &lt; productRows; i++){
        console.log("QTY: "+ productQty[i]);
        console.log("Name: "+ productName[i]);
        console.log("Value: "+ productValue[i]);
  
        var name = productName[i];
        var qty = productQty[i];
        var price = productValue[i];
  
  
       _gaq.push(['_addItem',
        orderID,           // order ID - required
        'Ecommerce',           // SKU/code - required
        ''+name+'',        // product name
        '',   // category or variation
        ''+price+'',          // unit price - required
        ''+qty+''               // quantity - required
      ]);
  
    }
  
      _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
  
  
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  
  } // Ecommerce GA Code
  
  function noEcommerceGA(){
  
        console.log("Normal GA Launched");
        _gaq.push(['_setAccount', 'UA-2167264-1']);
        _gaq.push(['_setDomainName', '.convio.net']);
        _gaq.push(['_setAllowLinker', true]);
        _gaq.push(['_setSiteSpeedSampleRate', 5]);
          if (CONVIO.referrer.length != 0) {
              _gaq.push(['_setReferrerOverride',CONVIO.referrer]);      
          }
        _gaq.push(['_trackPageview']);
  
  
          var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
          ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
          var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  
  } // no Ecommerce Code
  &lt;/script&gt;
  
  &lt;table class="ShoppingCart" cellpadding="5" border="1" style="border-collapse: collapse;" width="100%"&gt;
    &lt;tbody&gt;
      &lt;tr class="ShoppingCartHeadings"&gt;
        &lt;th width="10%"&gt; &lt;p&gt;Quantity&lt;/p&gt;
        &lt;/th&gt;
        &lt;th width="70%"&gt; &lt;p&gt;Item Name&lt;/p&gt;
        &lt;/th&gt;
        &lt;th width="20%"&gt; &lt;p&gt;Total Price&lt;/p&gt;
        &lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr valign="top" class="ShoppingCartRow0"&gt;
        &lt;td&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;
        &lt;td&gt;&lt;p&gt; &lt;span class="CartItemName"&gt;Interview with a Terrorist&lt;/span&gt; ($5.00 each) &lt;/p&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;p&gt;$5.00&lt;/p&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td colspan="2" align="right"&gt;&lt;p&gt;&lt;strong&gt;Total Price of Items:&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;p&gt;&lt;strong&gt;$5.00&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td colspan="2" align="right"&gt;&lt;p&gt; &lt;strong&gt;Shipping Charges: &lt;/strong&gt; &lt;/p&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;p&gt;&lt;strong&gt;$5.00&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td colspan="2" align="right"&gt;&lt;p&gt;&lt;strong&gt;Total: &lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;p&gt;&lt;strong&gt;$10.00&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>As you can probably see as well, I even attempt to remove extra spaces from the variable values.</p>
  
  <p>In my console tests, everything is a single line string with no linebreaks, so I have no clue what the heck is going on.</p>
  
  <p>Any help would be appreciated. Thanks!</p>