2012-09-15 56 views
0

试图让GA建立与我们的电子商务商店运行到哪里实际产品的项目没有在所有GA发布的问题。总价工作正常,但没有任何项目数据通过。谷歌分析代码换行符[“_ addTrans”

在Chrome中使用Google Analytics(分析)调试器,看起来好像发生了这种情况,因为变量返回的值位于单独的行上。谷歌认为它没有任何价值,至少看起来像什么似的。

我附加了一个调试器窗口的屏幕来显示换行符

enter image description here

之前,你看看代码,请注意,为了得到价值和产品的定价,我必须遍历对电子商务的表感谢页面,因为电子商务系统,我们使用没有按”吨有任何API的...

下面是与在测试顺序导出的表的代码。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 
<script type="text/javascript"> 
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("[\\?&]"+key+"=([^&#]*)"); 
     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 <= 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 < 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 < 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 
</script> 

<table class="ShoppingCart" cellpadding="5" border="1" style="border-collapse: collapse;" width="100%"> 
    <tbody> 
    <tr class="ShoppingCartHeadings"> 
     <th width="10%"> <p>Quantity</p> 
     </th> 
     <th width="70%"> <p>Item Name</p> 
     </th> 
     <th width="20%"> <p>Total Price</p> 
     </th> 
    </tr> 
    <tr valign="top" class="ShoppingCartRow0"> 
     <td><p>1</p></td> 
     <td><p> <span class="CartItemName">Interview with a Terrorist</span> ($5.00 each) </p></td> 
     <td align="right"><p>$5.00</p></td> 
    </tr> 
    <tr> 
     <td colspan="2" align="right"><p><strong>Total Price of Items:</strong></p></td> 
     <td align="right"><p><strong>$5.00</strong></p></td> 
    </tr> 
    <tr> 
     <td colspan="2" align="right"><p> <strong>Shipping Charges: </strong> </p></td> 
     <td align="right"><p><strong>$5.00</strong></p></td> 
    </tr> 
    <tr> 
     <td colspan="2" align="right"><p><strong>Total: </strong></p></td> 
     <td align="right"><p><strong>$10.00</strong></p></td> 
    </tr> 
    </tbody> 
</table> 

正如你可能也看到,我甚至试图从变量值中删除多余的空格。

在我的控制台测试,一切都是单行线,没有换行符,所以我不知道究竟发生了什么事。

任何帮助,将不胜感激。谢谢!

+0

?CONFIRMATION =真激活电子商务GA代码。必须这样做,因为没有API可以告诉用户何时登陆内置的感谢页面。 – Ian

回答

0

一个问题:所有的产品具有相同的SKU:“电子商务”。从Ecommerce tracking code docs

确保库存中的每件商品都具有唯一的SKU。 如果您的库存有相同的SKU不同的项目,以及访问者购买他们两个,您将收到的数据仅最近添加的

如果您的购物车表中没有某种产品ID或SKU,则可以将产品名称用于SKU和产品名称参数。

+0

这是有道理的。这样它仍然保持独特。我会做出改变,看看是否能解决整体问题......如果有什么数据会更清洁! – Ian