我在电子商务网站收据页面上有跟踪脚本。该脚本只是从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的任何销售。
我会接受第一个导致我解决这个问题的答案。
答案 0 :(得分:0)
我们想通了。事实证明,OpenTag正在将URL“//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js”转换为“////ajax.googleapis.com/ajax/libs/jquery” /1.8.0/jquery.min.js“仅在Internet Explorer中。我们通过使用JavaScript来确定协议来解决它。