gaq_push 未定义:谷歌分析错误
我已经实现了新的“异步”谷歌分析片段。这是片段:
<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 -->
但是,我收到一条错误消息:Uncaught ReferenceError: gaq_push is not defined
DMI:Expression 代码是用于传递变量的内部 API 代码。如您所见,我正在传递 ItemTotal、Tax 等内容。
但是,我相信错误出现在交易跟踪区域。有任何想法吗?