Javascript Google Analytics GTag.js带有UA属性和GA4属性,只有UA属性接收添加到购物车事件
我的网站有问题,无法编辑服务器源代码。在标题中,我使用gtag实现标准的Google Analytics安装Javascript Google Analytics GTag.js带有UA属性和GA4属性,只有UA属性接收添加到购物车事件,javascript,jquery,google-analytics,google-analytics-4,Javascript,Jquery,Google Analytics,Google Analytics 4,我的网站有问题,无法编辑服务器源代码。在标题中,我使用gtag实现标准的Google Analytics安装 <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); gtag('config', 'UA-XXXX
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
gtag('config', 'UA-XXXXXXXX-1');
</script>
window.dataLayer=window.dataLayer | |[];
函数gtag(){dataLayer.push(参数);}
gtag('js',新日期());
gtag('config','G-xxxxxxxxx');
gtag(“配置”、“UA-XXXXXXXX-1”);
当我发送下面的add-to-cart事件时,事件和产品信息由UA属性收集,但GA4属性都不收集。当我使用JSON.Stringify变量时,我在ga4属性中获得add-to-cart事件,但没有产品
我使用的是GA4结构,它说它是向后兼容的
jQuery(document).ready(function () {
// Search transaction products. Add each project to an Object. Then add each Object in to an array
const cmbaordertable = document.querySelector("[id*='ShoppingCart_ItemGrid'] tbody");
const cmbaordertablelength = document.querySelector("[id*='ShoppingCart_ItemGrid'] tbody").rows.length;
const cartProducts = []
for (i = 0; i < cmbaordertablelength; i++) {
const productSku = String(cmbaordertable.rows[i].cells[6].innerHTML.split("-")[1]);
const productCat = String(cmbaordertable.rows[i].cells[6].innerHTML.split("-")[0]);
const productNameHTML = cmbaordertable.rows[i].cells[0].innerHTML;
const productName = String(productNameHTML.replace(/(<([^>]+)>)/ig,""));
const productPrice = Number(cmbaordertable.rows[i].cells[2].innerHTML);
//const productQuantity = Number(cmbaordertable.rows[i].cells[1].children[0].value);
const productQuantity = Number(cmbaordertable.rows[i].cells[1].innerHTML);
const index = i+1;
const cartProduct = {
"id": productSku,
"name": productName,
"category": "Event",
"index": index,
"quantity": productQuantity,
"price": productPrice
};
cartProducts.push(cartProduct);
}
const cartProductsFinal = JSON.stringify(cartProducts)
console.log(cartProductsFinal);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', { 'send_page_view': false });
gtag('config', 'UA-XXXXXXXXXX-1', { 'send_page_view': false });
gtag('event', 'add_to_cart', {
'currency': 'USD',
'items' : [
cartProducts
]
});
});
</script>
jQuery(文档).ready(函数(){
//搜索交易产品。将每个项目添加到对象。然后将每个对象添加到数组中
常量cmbaordertable=document.querySelector(“[id*='ShoppingCart\u ItemGrid']tbody”);
const cmbaordertablelength=document.querySelector(“[id*='ShoppingCart\u ItemGrid']tbody”).rows.length;
const cartProducts=[]
对于(i=0;i)/ig,“”);
const productPrice=Number(cmbaordertable.rows[i].cells[2].innerHTML);
//const productQuantity=Number(cmbaordertable.rows[i]。单元格[1]。子项[0]。值);
const productQuantity=Number(cmbaordertable.rows[i].cells[1].innerHTML);
常数指数=i+1;
常数产品={
“id”:产品SKU,
“名称”:productName,
“类别”:“事件”,
“索引”:索引,
“数量”:产品数量,
“价格”:产品价格
};
cartProducts.push(cartProduct);
}
const cartProductsFinal=JSON.stringify(cartProducts)
console.log(cartProductsFinal);
window.dataLayer=window.dataLayer | |[];
函数gtag(){dataLayer.push(参数);}
gtag('js',新日期());
gtag('config','G-xxxxxxxxx',{'send_page_view':false});
gtag('config','UA-XXXXXXXXX-1',{'send_page_view':false});
gtag(‘事件’、‘添加到购物车’{
“货币”:美元,
“项目”:[
手推车产品
]
});
});
问得好,我也有同样的问题