我在電子商務網站收據頁上有一個跟蹤腳本。該腳本只是從DOM獲取產品信息並使用Piwik電子商務追蹤功能進行追蹤。這適用於除Internet Explorer 8及以下版本以外的所有瀏覽器。我一直在努力弄清楚這個劇本有什麼問題。我已經在虛擬收據頁面本地測試了它,並且它在IE中正常工作,但它並沒有跟蹤實時頁面上任何針對IE 5-8的銷售情況。Piwik跟蹤腳本在除IE8以及以下的所有瀏覽器上工作
跟蹤腳本通過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上是我的最後一招,我不能爲我的生活弄清楚這是爲什麼不跟蹤互聯網的任何銷售探索者5-8。
我會接受導致我解決此問題的第一個答案。