未定义gaq_push:Google Analytics错误
我实施了新的“Async”Google Analytics代码段。这是片段:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16558786-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
在我的订单页面上,我正在跟踪这样的交易:
<!-- google receipt begin -->
<script language="JavaScript" type="text/javascript">
// total transaction
gaq_push._addTrans(
"[[DMI:Expression value='((Order)Container.DataItem).OrderNumber']][[/DMI:Expression]]", // order ID - required
"A.M. Leonard", // affiliation or store name
"[[DMI:Expression value='((Order)Container.DataItem).ItemTotal.ToString("0.00")']][[/DMI:Expression]]", // total - required
"[[DMI:Expression value='((Order)Container.DataItem).Tax.ToString("0.00")' ]][[/DMI:Expression]]", // tax
"[[DMI:Expression value='((Order)Container.DataItem).ShippingCost.ToString("0.00")' ]][[/DMI:Expression]]", // shipping
"[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.City' ]][[/DMI:Expression]]", // city
"[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.State' ]][[/DMI:Expression]]", // state or province
"[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.Country' ]][[/DMI:Expression]]" // country
);
// all items
[[DMI:Use dmisource='((Order)Container.DataItem).Items']]
gaq_push._addItem(
"[[DMI:Expression value='((OrderItem)Container.DataItem).OrderNumber' ]][[/DMI:Expression]]", // order ID - necessary to associate item with transaction
"[[DMI:Expression value='((OrderItem)Container.DataItem).Sku' ]][[/DMI:Expression]]", // SKU/code - required
"[[DMI:Expression value='Core.URLEncode(((OrderItem)Container.DataItem).ProductName)' ]][[/DMI:Expression]]", // product name
"", // category or variation
"[[DMI:Expression value='((OrderItem)Container.DataItem).UnitPrice.ToString("0.00")' ]][[/DMI:Expression]]", // unit price - required
"[[DMI:Expression value='((OrderItem)Container.DataItem).QtyOrdered' ]][[/DMI:Expression]]" // quantity - required
);
[[/DMI:Use]]
gaq_push._trackTrans(); //submits transaction to the analytics servers
</script>
<!-- google receipt end -->
但是,我收到一条错误消息:未捕获的ReferenceError:未定义gaq_push
DMI:表达式代码是用于传递变量的内部API代码。正如你所看到的,我正在传递诸如ItemTotal,Tax等等的东西。
但是,我认为错误发生在“事务跟踪”区域。有什么想法吗?
答案 0 :(得分:1)
大多数跟踪代码段都包含以下内容:
var _gaq = _gaq || [];
确保定义_gaq.push()
等,无论GA是否已满载。
请参阅此相关问题: What is "var _gaq = _gaq || []; " for?
答案 1 :(得分:0)
您收到该错误是因为您的GA电子商务脚本中未定义gaq。
根据(Google Analytics异步电子商务跟踪)[https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce]页面,您应该声明gaq,设置帐户以及发送跟踪综合报道。