问题描述
我无法将服务器源代码编辑到的站点有问题。在标题中,我正在使用gtag实施标准的Google Analytics(分析)安装
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js',new Date());
gtag('config','G-XXXXXXXXXX');
gtag('config','UA-XXXXXXXX-1');
</script>
当我发送以下添加到购物车事件时,该事件和产品信息由UA属性收集,而GA4属性均未收集。当我使用JSON.Stringify变量时,我在GA 4属性中获得了添加到购物车事件,但没有任何产品。
我正在使用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>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)