谷歌分析通用电子商务数据未被记录
Google Analytics Universal Ecommerce data not being recorded
我一直试图移动我的谷歌分析电子商务跟踪到通用,但我有一些问题。跟踪本身工作良好,但不是电子商务。我已经启用了电子商务跟踪谷歌分析,并添加了以下代码:
在printerlandtest.co.uk.cara.init.js:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-30033504-40', 'auto',{'name': 'CARATracker'}); // New tracker.
ga('CARATracker.send', 'pageview');
和内部caranew.js
ga('CARATracker.require', 'ec');
function CaraGetWidgetDescription(manufacturerWidget) {
CaraConfig();
ga('CARATracker.set', 'Widget Impression ID E-tale', String(manufacturerWidget));
}
function CaraAddToBasket(productName, sku) {
CaraConfig();
ga('CARATracker.send', 'event', String(productName), 'AddToBasket', String(sku));
}
function CaraBeginTransaction(orderNo, totalPrice) {
CaraConfig();
ga('CARATracker.ecommerce:addTransaction', String(orderNo), "", CaraPriceFix(String(totalPrice)), "", "0.00", "", "", "");
}
function CaraAddTransactionItem(orderNo, sku, productName, productCategory, productPrice, quantity) {
CaraConfig();
ga('CARATracker.ecommerce:addItem', {
String(orderNo),
String(sku),
String(productName),
String(productCategory),
CaraPriceFix(String(productPrice)),
String(quantity)
});
function CaraEndTransaction() {
CaraConfig();
ga('CARATracker.ecommerce:send');
}
function CaraPriceFix(price) {
var fixedPrice = price;
var pLength = price.length;
var comma = price.indexOf(",") + 1;
var period = price.indexOf(".") + 1;
//comma is in the price
if (comma != 0) {
//if the comma is not at a 2-decimal point position
//i.e true for 1,200
if ((pLength - comma) > 2) {
fixedPrice = fixedPrice.replace(",", "");
}
}
//period is in the price
if (period != 0) {
//if the period is not at a 2-decimal point position
//i.e true for 1.200
if ((pLength - period) > 2) {
fixedPrice = fixedPrice.replace(".", "");
}
}
return fixedPrice;
}
由于这是在一个客户的网站,它是异步与自己的谷歌分析,并设置如下:
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-3521256-1', {'siteSpeedSampleRate': 20}); ga('send', 'pageview');</script><script src="https://where-to-buy.co/scripts/cara/printerlandtest.co.uk.cara.init.js" type="text/javascript"></script><script src="https://where-to-buy.co/scripts/cara/caranew.js" type="text/javascript"></script>
添加到购物篮按钮的代码如下:
<a onclick="TrackEvent('Buy Button Click','ProductList','01327701','');CaraAddToBasket('OKI C511dn','01327701');" id="ctl00_ctl00_ContentPlaceHolderMain_cntPlaceHlderMain_lstCategoryProducts_ctrl0_lnkBuy" class="button product_buy selected" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ContentPlaceHolderMain$cntPlaceHlderMain$lstCategoryProducts$ctrl0$lnkBuy", "", true, "", "", false, true))'><span>Added</span> </a>
然而,我得到以下错误:
Uncaught ReferenceError: CaraAddToBasket is not defined
,当我点击支付,我得到以下错误:
Uncaught ReferenceError: CaraBeginTransaction is not defined
我以为我在函数中定义了它们,但我有错吗?
还有什么可以阻止电子商务跟踪吗?
谢谢
我重写了代码,得到了这个解决方案。删除所有新的String()函数,并将price fix函数移出数组,放到它上面的一个var中。
还有一个addtobasket函数后面缺少},导致JS失败。
现在函数运行正常。
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-30033504-40', 'auto', {
'name': 'CARATracker'
}); // New tracker.
ga('CARATracker.send', 'pageview');
ga('CARATracker.require', 'ec');
function CaraGetWidgetDescription(manufacturerWidget) {
CaraConfig();
ga('CARATracker.set', 'Widget Impression ID E-tale', String(manufacturerWidget));
}
function CaraAddToBasket(productName, sku) {
CaraConfig();
ga('CARATracker.send', 'event', String(productName), 'AddToBasket', String(sku));
alert('Debugging: added');
}
function CaraBeginTransaction(orderNo, totalPrice) {
CaraConfig();
ga('CARATracker.ecommerce:addTransaction', String(orderNo), "", CaraPriceFix(String(totalPrice)), "", "0.00", "", "", "");
}
function CaraAddTransactionItem(orderNo, sku, productName, productCategory, productPrice, quantity) {
CaraConfig();
var price = CaraPriceFix(productPrice);
alert(price);
ga('CARATracker.ecommerce:addItem', {
orderNo,
sku,
productName,
productCategory,
price,
quantity
});
}
function CaraEndTransaction() {
CaraConfig();
ga('CARATracker.ecommerce:send');
}
function CaraPriceFix(price) {
var fixedPrice = price;
var pLength = price.length;
var comma = price.indexOf(",") + 1;
var period = price.indexOf(".") + 1;
//comma is in the price
if (comma != 0) {
//if the comma is not at a 2-decimal point position
//i.e true for 1,200
if ((pLength - comma) > 2) {
fixedPrice = fixedPrice.replace(",", "");
}
}
//period is in the price
if (period != 0) {
//if the period is not at a 2-decimal point position
//i.e true for 1.200
if ((pLength - period) > 2) {
fixedPrice = fixedPrice.replace(".", "");
}
}
return fixedPrice;
}
function CaraConfig() {
//empty
}
<html>
<body>
<a onclick="CaraAddToBasket('OKI C511dn','01327701');" id="ctl00_ctl00_ContentPlaceHolderMain_cntPlaceHlderMain_lstCategoryProducts_ctrl0_lnkBuy" class="button product_buy selected" href='#'><span>Added</span> </a>
</body>
</html>
相关文章:
- 更新成员数据模型中的记录列表
- 在页面上记录数据并实现pushstate()的最佳方式
- Firebase:如何从存在特定密钥的数据中检索记录
- 数据中的一条记录使用浮动图时未创建饼图
- Chrome扩展-使用javascript定期运行,并永久记录数据
- 在本地使用浏览器历史记录时刷新页面后数据消失
- 使用 Prepare 语句插入数据不会返回插入的记录
- 单击事件不起作用,当我在 jquery 数据表中显示每页 25 条记录时
- lunr.js添加有关索引记录的数据
- 数据表:禁用第一个下一个上一个最后一个,并在处理时显示/搜索记录
- 基于表单输入值,如何 2 生成选择 4 下拉菜单 w 数据库中的行/记录数据,该数据库将在选择时预填充表单
- 如何为下拉菜单生成选择,其中包含数据库中的行/记录数据,该数据库将在选择时预填充表单
- 根据内部数组值跳过 JSON 数据记录 - D3
- 在Ember.js Ember数据记录数组上迭代
- JSON数据记录到缓冲区,PUT到服务器
- 使用Ajax调用接收数据记录的问题
- 将检索到的Ember数据记录转换为普通对象的Ember方式是什么?
- 为每个JSON数据记录添加对象
- 如何在 Web 中播放来自 Android 的原始样本PCM_16音频数据记录(使用网络音频或其他)
- Angular不会更新DOM,但会把数据记录到控制台