Google Analytics(分析)电子商务提交交易无效 [英] Google analytics Ecommerce Submit transaction is not working

查看:92
本文介绍了Google Analytics(分析)电子商务提交交易无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从analytics.js复制基本示例并硬编码参数时,

提交事务工作正常,这里使用异步方法示例。当我试图从网站传递动态价值时,它不提交交易。

请找到以下代码并更新并帮助



< pre lang =cs> $。ajax({
type: POST
url: / WSHub / wsTransactionReceipt.asmx / GetOrderDetailsforanalytics
data :JSON.stringify(sdata),
contentType: application / json; charset = utf-8
dataType: json
success:function(数据){
var 总计= 0 ;
for var i = 0 ; i < data.d.length; i ++){
Total = Total + parseFloat(data.d [i] .UnitPrice);
}
var _gaq = _gaq || [];
_gaq.push([' _ setAccount'' UA-48304226-1']);
_gaq.push([' _ trackPageview']);
_gaq.push([' _ addTrans'
' ' + objResult.SalesOrderNumber + ' ' // 交易ID - 必填
' ' // 从属关系或商店名称
' '' +总计+ ' ' // total - required
' ', // tax
' ' // shipping
' ' // city
' ' // 州或省
' ' // country
]);
for var i = 0 ; i < data.d.length; i ++){
// < span class =code-comment> debugger;
// 可能会调用添加项目对于购物车中的每件商品
// 您的电子商务引擎在其中循环显示每个商品购物车和
// 为每个
打印出_addItem _gaq.push([' _ addItem'
' ' + objResult.SalesOrderNumber + ' ' // 交易ID - 必填
' ' + data.d [i] .SKUName + ' ' // SKU /代码 - 必需
' ' + data.d [i] .ProductName + ' ' // 产品名称
' ' // 类别或变体
' < span class =code-string>' + data.d [i] .UnitPrice + ' ' // 单价 - 必需
' ' + data.d [i] .Quantity + ' ' // 数量 - 必填
]);
}
_gaq.push([' _ trackTrans']); // 将事务提交给Analytics服务器
(function(){
< span class =code-keyword> var ga = document.createElement(' script'); ga.type = ' text / javascript'; ga。 async = true ;
ga.src =(' < span class =code-string> https:' == document.location.protocol?' https :// ssl'' http:// www')+ ' 。google-analytics.com/ga.js';
var s = document.getElementsByTagName(' script')[ 0 ]; s.parentNode.insertBefore(ga,s);
})();
}
});

解决方案

.ajax({
type: POST
url: < span class =code-string> / WSHub / wsTransactionReceipt.asmx / GetOrderDetailsforanalytics,
data:JSON.stringify(sdata),
contentType: application / json; charset = utf-8
dataType: json
成功:函数(数据){
var 总计= 0 ;
for var i = 0 ; i < data.d.length; i ++){
Total = Total + parseFloat(data.d [i] .UnitPri ce);
}
var _gaq = _gaq || [];
_gaq.push([' _ setAccount'' UA-48304226-1']);
_gaq.push([' _ trackPageview']);
_gaq.push([' _ addTrans'
' ' + objResult.SalesOrderNumber + ' ' // 交易ID - 必填
' ' // 从属关系或商店名称
' '' +总计+ ' ' // total - required
' ', // tax
' ' // shipping
' ' // city
' ' // 州或省
' ' // country
]);
for var i = 0 ; i < data.d.length; i ++){
// < span class =code-comment> debugger;
// 可能会调用添加项目对于购物车中的每件商品
// 您的电子商务引擎在其中循环显示每个商品购物车和
// 为每个
打印出_addItem _gaq.push([' _ addItem'
' ' + objResult.SalesOrderNumber + ' ' // 交易ID - 必填
' ' + data.d [i] .SKUName + ' ' // SKU /代码 - 必需
' ' + data.d [i] .ProductName + ' ' // 产品名称
' ' // 类别或变体
' < span class =code-string>' + data.d [i] .UnitPrice + ' ' // 单价 - 必需
' ' + data.d [i] .Quantity + ' ' // 数量 - 必填
]);
}
_gaq.push([' _ trackTrans']); // 将事务提交给Analytics服务器
(function(){
< span class =code-keyword> var ga = document.createElement(' script'); ga.type = ' text / javascript'; ga。 async = true ;
ga.src =(' < span class =code-string> https:' == document.location.protocol?' https :// ssl'' http:// www')+ ' 。google-analytics.com/ga.js';
var s = document.getElementsByTagName(' script')[ 0 ]; s.parentNode.insertBefore(ga,s);
})();
}
});


Submit transaction is working fine when iam copy the basic example from analytics.js and hard code the parameter ,here iam using asynchronous method example. When i trying to pass dynamic valus from site it is not submitting transaction .
Please find the below code and update it and help

$.ajax({
        type: "POST",
        url: "/WSHub/wsTransactionReceipt.asmx/GetOrderDetailsforanalytics",
        data: JSON.stringify(sdata),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var Total = 0;
            for (var i = 0; i < data.d.length; i++) {
                Total = Total + parseFloat(data.d[i].UnitPrice);
            }
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-48304226-1']);
            _gaq.push(['_trackPageview']);
            _gaq.push(['_addTrans',
                    '"' + objResult.SalesOrderNumber + '"',         // transaction ID - required
                    '',                                             // affiliation or store name
                    '"' + Total + '"',                              // total - required
                    '',                                             // tax
                    '',                                             // shipping
                    '',                                             // city
                    '',                                             // state or province
                    ''                                              // country
                  ]);
            for (var i = 0; i < data.d.length; i++) {
               // debugger;
                // add item might be called for every item in the shopping cart
                // where your ecommerce engine loops through each item in the cart and
                // prints out _addItem for each
                _gaq.push(['_addItem',
                    '"' + objResult.SalesOrderNumber + '"',    // transaction ID - required
                    '"' + data.d[i].SKUName + '"',             // SKU/code - required
                    '"' + data.d[i].ProductName + '"',         // product name
                    '',                                        // category or variation
                    '"' + data.d[i].UnitPrice + '"',           // unit price - required
                    '"' + data.d[i].Quantity + '"'             // quantity - required
                  ]);
            }
            _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
            (function () {
                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);
            })();
        }
    });

解决方案

.ajax({ type: "POST", url: "/WSHub/wsTransactionReceipt.asmx/GetOrderDetailsforanalytics", data: JSON.stringify(sdata), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { var Total = 0; for (var i = 0; i < data.d.length; i++) { Total = Total + parseFloat(data.d[i].UnitPrice); } var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-48304226-1']); _gaq.push(['_trackPageview']); _gaq.push(['_addTrans', '"' + objResult.SalesOrderNumber + '"', // transaction ID - required '', // affiliation or store name '"' + Total + '"', // total - required '', // tax '', // shipping '', // city '', // state or province '' // country ]); for (var i = 0; i < data.d.length; i++) { // debugger; // add item might be called for every item in the shopping cart // where your ecommerce engine loops through each item in the cart and // prints out _addItem for each _gaq.push(['_addItem', '"' + objResult.SalesOrderNumber + '"', // transaction ID - required '"' + data.d[i].SKUName + '"', // SKU/code - required '"' + data.d[i].ProductName + '"', // product name '', // category or variation '"' + data.d[i].UnitPrice + '"', // unit price - required '"' + data.d[i].Quantity + '"' // quantity - required ]); } _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers (function () { 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); })(); } });


这篇关于Google Analytics(分析)电子商务提交交易无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆