我在使用 Google Analytics(分析)电子商务跟踪时遇到了一个奇怪的问题,我无法通过自己的实验、在此站点或 Google 上找到解决方案。
我们网站上的所有购买都是作为 javascript 单页 Web 应用程序的一部分发生的,并且页面重新加载通常不会在购买之间发生,除非用户专门访问了网站内的其他页面。我们的网站使用谷歌分析来跟踪页面浏览量、事件以及购买的电子商务跟踪。这已经工作了很长时间,并且仍然有效,但是我们的一位开发人员最近注意到,在进行 trackTrans 调用时,之前提交到 trackTrans 的事务和项目正在重新包含。这在 Google Chrome 网络选项卡(__utm 请求)中被注意到,并且已使用 Google 自己的 Chrome GA 调试扩展程序进行了验证。
让我通过调用和日志输出来说明问题(请注意,出于隐私原因,某些信息已被删除):
首次购买页面加载:
_gaq.push(['_addTrans', 872, (removed), 0.10, , , (removed), null, (removed)]); F3085D20782A2AC201B3D564B205E01B.cache.html:32780
_gaq.push processing "_addTrans" for args: "[872,(removed),0.10,,,(removed),,(removed)]": [VM] ga_debug.js (4049):24
_gaq.push(['_addItem', 872, Id#11474748#GameId#17, (removed), (removed), 0.10, 1]); F3085D20782A2AC201B3D564B205E01B.cache.html:32769
_gaq.push processing "_addItem" for args: "[872,Id#11474748#GameId#17,(removed),(removed),0.10,1]": [VM] ga_debug.js (4049):24
_gaq.push(['_trackTrans']); F3085D20782A2AC201B3D564B205E01B.cache.html:32813
_gaq.push processing "_trackTrans" for args: "[]": [VM] ga_debug.js (4049):24
Track Transaction [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=13&utmn=1580365368&utmhn=(removed)&utmt=tran&utmtid=872&utmtst=(removed)&utmtto=0.10&utmttx=&utmtsp=&utmtci=(removed)&utmtrg=null&utmtco=(removed)&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378732665904&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : tran
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Order ID : 872
Billing City : (removed)
Billing Region : null
Billing Country : (removed)
Affilliation : (removed)
Total : 0.10
Shipping Cost :
Tax :
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 1580365368 [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=14&utmn=2121074133&utmhn=(removed)&utmt=item&utmtid=872&utmipc=Id%2311474748%23GameId%2317&utmipn=(removed)&utmiva=(removed)&utmipr=0.10&utmiqt=1&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378732665904&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : item
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Product Code : Id#11474748#GameId#17
Product Name : (removed)
Unit Price : 0.10
Quantity : 1
Item Variation : (removed)
Order ID : 872
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 2121074133 [VM] ga_debug.js (4049):24
无需重新加载页面的第二次购买(同一会话):
_gaq.push(['_addTrans', 873, (removed), 0.10, , , (removed), null, (removed)]); F3085D20782A2AC201B3D564B205E01B.cache.html:32780
_gaq.push processing "_addTrans" for args: "[873,(removed),0.10,,,(removed),,(removed)]": [VM] ga_debug.js (4049):24
_gaq.push(['_addItem', 873, Id#26113584#GameId#17, (removed), (removed), 0.10, 1]); F3085D20782A2AC201B3D564B205E01B.cache.html:32769
_gaq.push processing "_addItem" for args: "[873,Id#26113584#GameId#17,(removed),(removed),0.10,1]": [VM] ga_debug.js (4049):24
_gaq.push(['_trackTrans']); F3085D20782A2AC201B3D564B205E01B.cache.html:32813
_gaq.push processing "_trackTrans" for args: "[]": [VM] ga_debug.js (4049):24
Track Transaction [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=20&utmn=2023058614&utmhn=(removed)&utmt=tran&utmtid=872&utmtst=(removed)&utmtto=0.10&utmttx=&utmtsp=&utmtci=(removed)&utmtrg=null&utmtco=(removed)&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378733392697&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : tran
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Order ID : 872
Billing City : (removed)
Billing Region : null
Billing Country : (removed)
Affilliation : (removed)
Total : 0.10
Shipping Cost :
Tax :
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 2023058614 [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=21&utmn=428191029&utmhn=(removed)&utmt=item&utmtid=872&utmipc=Id%2311474748%23GameId%2317&utmipn=(removed)&utmiva=(removed)&utmipr=0.10&utmiqt=1&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378733392698&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : item
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Product Code : Id#11474748#GameId#17
Product Name : (removed)
Unit Price : 0.10
Quantity : 1
Item Variation : (removed)
Order ID : 872
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 428191029 [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=22&utmn=2054976501&utmhn=(removed)&utmt=tran&utmtid=873&utmtst=(removed)&utmtto=0.10&utmttx=&utmtsp=&utmtci=(removed)&utmtrg=null&utmtco=(removed)&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378733392698&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : tran
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Order ID : 873
Billing City : (removed)
Billing Region : null
Billing Country : (removed)
Affilliation : (removed)
Total : 0.10
Shipping Cost :
Tax :
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 2054976501 [VM] ga_debug.js (4049):24
Tracking beacon sent!
utmwv=5.4.4d&utms=23&utmn=900028249&utmhn=(removed)&utmt=item&utmtid=873&utmipc=Id%2326113584%23GameId%2317&utmipn=(removed)&utmiva=(removed)&utmipr=0.10&utmiqt=1&utme=8(ageGender)9(M%2065%2B)11(2)&utmcs=UTF-8&utmsr=2560x1440&utmvp=2560x1352&utmsc=24-bit&utmul=en-gb&utmje=1&utmfl=11.8%20r800&utmdt=(removed)&utmhid=1366812599&utmr=-&utmp=(removed)&utmht=1378733392699&utmac=(removed)&utmcc=__utma%3D162785085.187708818.1377079516.1378725565.1378732612.33%3B%2B__utmz%3D162785085.1377079516.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=6xCL~ [VM] ga_debug.js (4049):24
Account ID : (removed)
Page Title : (removed)
Host Name : (removed)
Page : (removed)
Referring URL : -
Hit ID : 1366812599
Hit Type : item
Visitor ID : 187708818
Session Count : 33
Session Time - First : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Session Time - Last : Mon Sep 09 2013 12:19:25 GMT 0100 (BST)
Session Time - Current : Mon Sep 09 2013 14:16:52 GMT 0100 (BST)
Campaign Time : Wed Aug 21 2013 11:05:16 GMT 0100 (BST)
Campaign Session : 1
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
Custom Var 1 : label:'ageGender' value:'M 65 ' scope:'2'
Product Code : Id#26113584#GameId#17
Product Name : (removed)
Unit Price : 0.10
Quantity : 1
Item Variation : (removed)
Order ID : 873
Language : en-gb
Encoding : UTF-8
Flash Version : 11.8 r800
Java Enabled : true
Screen Resolution : 2560x1440
Browser Size : 2560x1352
Color Depth : 24-bit
Ga.js Version : 5.4.4d
Cachebuster : 900028249 [VM] ga_debug.js (4049):24
首次购买时会发送两个跟踪信标:
- 订单 ID 为“872”的命中类型“tran”之一
- 订单 ID 为“872”且产品代码 (SKU) 为“Id#11474748#GameId#17”的命中类型“项目”之一
这是对的。
对于第二次购买,将发送四个跟踪信标:
- 订单 ID 为“872”的命中类型“tran”之一(上一笔交易)
- 订单 ID 为“872”且产品代码 (SKU) 为“Id#11474748#GameId#17”的命中类型“项目”之一(上一个项目)
- 订单 ID 为“873”的命中类型“tran”之一(新交易)
- 订单 ID 为“873”且产品代码 (SKU) 为“Id#26113584#GameId#17”的命中类型“项目”之一(新项目)
虽然后面的跟踪信标是正确的,但前两个是第一次购买的重复,这是错误的。
随后的购买将看到发送 6、8、10 个等跟踪信标,其中第一个信标来自所有先前的购买,而不仅仅是最近的购买。
根据我们应用程序中的定义,产品代码 (SKU) 对于所有购买都是唯一的。我们的代码已经过验证,不会进行额外的 javascript 电子商务跟踪调用。这也通过直接在 Chrome 控制台中执行 javascript 电子商务调用得到验证,并看到以前交易的相同问题作为最新交易的一部分重新提交,似乎独立于我们的应用程序。
我们已经在生产分析中验证了重复购买(不止一次购买具有相同的 SKU),因此这会影响我们的报告(谢天谢地,我们的大部分财务报告是通过来自我们的数据库而不是 Google Analytics 的报告完成的)。
另请注意,在按照文档中的指定执行电子商务跟踪代码之前,肯定会跟踪页面浏览量!
任何确定问题的帮助将不胜感激!
- 更新
我已经使用下面的 html 在我们的应用程序之外运行一个简单的测试用例重现了这个问题(运行前需要输入 Google Analytics 帐户 ID,我从一个简单的 apache 服务器运行文件):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9;IE=8"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta name="viewport" content="maximum-scale=1.0, width=device-width"/>
<script type="text/javascript">
/*<![CDATA[*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); /* REPLACE WITH YOUR OWN ACCOUNT ID */
_gaq.push(['_setDomainName', 'none']); /* Must be set to none when running from localhost, but normally set to auto in Prod */
_gaq.push(['_setAllowLinker', false]); /* set to true in Prod but doesn't seem to have any effect on the issue */
(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);
})();
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
var orderId = 1;
var sku = 200;
makePurchase = function() {
console.error("...NEW PURCHASE HAPPENING..."); /* Error level just so it's easy to see in the console when a new purchase starts */
_gaq.push(['_trackPageview', '/purchase/complete']);
console.log("Tracking purchase for order with id " + orderId + " and SKU " + sku);
_gaq.push(['_addTrans', orderId, 'Acme Clothing', '11.99', '1.29' , '5', 'San Joes', 'California', 'USA']);
_gaq.push(['_addItem', orderId, sku, 'T-Shirt', 'Green Medium', '11.99', '1']);
_gaq.push(['_trackTrans']);
incrementOrderIds();
}
var incrementOrderIds = function() {
orderId = orderId + 1;
sku = sku + 10;
}
/*]]>*/
</script>
<title>Google Analytics Ecommerce Test Page</title>
</head>
<body>
<h1>Google Analytics Ecommerce Test</h1>
<div>
<a href="#" onclick="makePurchase()">Make Purchase</a>
</div>
</body>
</html>