简体   繁体   English

Piwik跟踪脚本可在除IE8及以下版本的所有浏览器上运行

[英]Piwik tracking script working on all browsers except IE8 and below

I have a tracking script on an E-commerce site receipt page. 我在电子商务网站收据页面上有一个跟踪脚本。 The script simply fetches the product information from the DOM and tracks it using the Piwik E-commerce tracking functions. 该脚本仅从DOM中获取产品信息,并使用Piwik电子商务跟踪功能对其进行跟踪。 This works fine in all browsers except Internet Explorer 8 and below. 在Internet Explorer 8及以下版本以外的所有浏览器中,此功能均正常运行。 I've been trying to figure out what's wrong with the script for weeks. 数周以来,我一直在试图弄清脚本出了什么问题。 I've tested it locally on a dummy receipt page and it works fine in IE, but it's not tracking any sales for IE 5-8 on the live page. 我已经在虚拟收据页面上对其进行了本地测试,它在IE中可以正常工作,但是它并未在实时页面上跟踪IE 5-8的任何销售情况。

The tracking script is inserted to the receipt page via an OpenTag tag and so is piwik.js, but I'm using the asynchronous tracker so that shouldn't be an issue, as all browsers except IE confirms. 跟踪脚本通过OpenTag标记插入到收据页面,piwik.js也是如此,但是我使用的是异步跟踪器,所以这应该不是问题,因为除IE之外的所有浏览器都已确认。

Here is the code that is injected via OpenTag: 这是通过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>

Asking on StackOverflow is my last resort, I can't for the life of me figure out why this isn't tracking any sales for Internet Explorer 5-8. 关于StackOverflow的问题是我的最后选择,我一生都无法弄清楚为什么它没有跟踪Internet Explorer 5-8的任何销售情况。

I'll accept the first answer that leads me to solve this issue. 我将接受引导我解决此问题的第一个答案。

We figured it out. 我们知道了。 It turns out OpenTag was transforming the URL "//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" into "////ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" only in Internet Explorer. 事实证明,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中。 We solved it by figuring out the protocol using JavaScript instead. 我们通过使用JavaScript找出协议来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM