我在电子商务网站收据页面上有一个跟踪脚本。该脚本只是从 DOM 中获取产品信息并使用 Piwik 电子商务跟踪功能对其进行跟踪。这适用于除 Internet Explorer 8 及以下版本之外的所有浏览器。几个星期以来,我一直在试图弄清楚脚本出了什么问题。我已经在虚拟收据页面上对其进行了本地测试,它在 IE 中运行良好,但它没有在实时页面上跟踪 IE 5-8 的任何销售。
跟踪脚本通过 OpenTag 标记插入到收据页面,piwik.js 也是如此,但我使用的是异步跟踪器,因此这不应该成为问题,因为除 IE 之外的所有浏览器都确认。
这是通过 OpenTag 注入的代码:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
// Closure that supports jQuery
(function($) {
// Function for removing everything from a string except numbers and
// returning that number as an integer
var num = function(text) {
return parseInt(text.replace(/[^0-9]/g, ''));
};
// Trims whitespace from before and after a string. " hello " => "hello"
var trim = function(text) {
return text.replace(/^\s+|\s+$/g, '');
};
// Run on document ready
$(function() {
// Ready a reference to Piwik async queue
_paq = _paq || [];
// Referansenummeret
var order_id = num(
$('span#ctl00_CPHCnt_McInPlaceEdYourRefNbr_McInPlaceEdYourRefNbr')
.closest('p').text()
);
// Hent verdien som ligger etter "Total:"
// var total = num(
// $('span#ctl00_CPHCnt_HandlevognProdukListe1_McInPlaceEdTotInclAVT2_McInPlaceEdTotInclAVT2')
// .closest('tr').children('td:last-child').text()
// );
var total = 0;
// Hent verdien som ligger etter "Sum:"
var sub_total = num(
$('span#ctl00_CPHCnt_HandlevognProdukListe1_McInPlaceEditorSum_McInPlaceEditorSum')
.closest('tr').children('td:last-child').text()
);
// Hent verdien som ligger etter "Herav mva:"
var mva = num(
$('table.CartSummaryTable .TotalValue').closest('tr').next()
.children('td:last-child').text()
);
// Hent verdien som ligger etter "Frakt inkl. evt. gebyr:"
var shipping = num(
$('span#ctl00_CPHCnt_HandlevognProdukListe1_McInPlaceEdFreightInclFee_McInPlaceEdFreightInclFee')
.closest('tr').children('td:last-child').text()
);
// Cheat solution - the total doesn't have a 100% hitrate so just
// add the sub_total and shipping together.
total = sub_total + shipping;
// Iterate over the product rows and extract the information
$('table#ProductList tr.VerticalText').each(function(index, row) {
var sku = trim($('td:first-child', row).text());
var prod_name = trim($('div.ProduktDesc span', row).text());
var categories = [];
var price = num($('td:nth-child(5)', row).text());
var quant = num($('td:nth-child(4)', row).text());
// Extrapolate categories from the product link URL
var path = $('.ProduktDesc a', row).attr('href').split('/');
for(var i = 2; i < path.length - 1; i++)
{
categories.push(path[i]);
}
// Track this product
_paq.push(['addEcommerceItem', sku, prod_name, categories, price, quant]);
});
// Track this order
_paq.push(['trackEcommerceOrder', order_id, total, sub_total, mva, shipping, false]);
});
}(window.jQuery.noConflict(true)));
</script>
在 StackOverflow 上询问是我最后的手段,我一辈子都想不通为什么这没有跟踪 Internet Explorer 5-8 的任何销售情况。
我会接受导致我解决此问题的第一个答案。