[英]Google Analytics gtag enhanced ecommerce add to cart event not recognizing product information
I am implementing Enhanced Ecommerce on a site and i am having issues with inserting the product data into the gtag event.我正在网站上实施增强型电子商务,但在将产品数据插入 gtag 事件时遇到问题。 Also the site is using version 1.11.2 of jQuery and i can't update from this.此外,该站点正在使用 jQuery 的 1.11.2 版本,我无法从中进行更新。
This code has been live for about 5 days on the site and when i use Firefox and Google Analytics Debugger it looks like everything should work, but when i console.log or print the response to a div the product info is not displayed.这段代码已经在网站上运行了大约 5 天,当我使用 Firefox 和 Google Analytics Debugger 时,看起来一切正常,但是当我 console.log 或打印对 div 的响应时,不会显示产品信息。
When i console.log(cartProducts);
当我console.log(cartProducts);
it logs the array as expected它按预期记录数组
{
id: "WC091119",
name: "Workers' Compensation Section Meeting",
category: "EVENT",
price: 0.00,
quantity: 1
}
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 = cmbaordertable.rows[i].cells[6].innerHTML.split("-")[1];
const productCat = cmbaordertable.rows[i].cells[6].innerHTML.split("-")[0];
const productNameHTML = cmbaordertable.rows[i].cells[0].innerHTML;
const productName = productNameHTML.replace(/(<([^>]+)>)/ig,"");
const productPrice = Number(cmbaordertable.rows[i].cells[2].innerHTML);
const productQuantity = Number(cmbaordertable.rows[i].cells[1].innerHTML);
// cartProducts.push(transactionName);
const cartProduct = {
id: productSku,
name: productName,
category: productCat,
price: productPrice,
quantity: productQuantity
};
cartProducts.push(cartProduct);
}
gtag('event', 'add_to_cart', {
"items": [
cartProducts
]
});
});
This is what i receive from the console这是我从控制台收到的
Executing Google Analytics commands. analytics.js:16:359
Running command: ga("gtag_UA_9915896_1.require", "ec", "ec.js") analytics.js:16:359
Running command: ga("gtag_UA_9915896_1.ec:addProduct", [{id: "REAL092619", name: "Real Estate Law Section Lunch Meeting & Guest Presentation", category: "EVENT", price: 0, quantity: 1}]) analytics.js:16:359
Running command: ga("gtag_UA_9915896_1.ec:setAction", "add", undefined) analytics.js:16:359
Running command: ga("gtag_UA_9915896_1.send", "event", {forceSSL: true, >m: "2ou9b0", hitCallback: [function], eventCategory: "ecommerce", eventAction: "add_to_cart"})
Any help is appreciated任何帮助表示赞赏
I did it using below code once.我用下面的代码做了一次。 Please see the below code whether It helps you.请查看以下代码是否对您有帮助。
for (var i = 0; i < vm.orderItems.length; i++) {
ga('ecommerce:addItem', {
'id': resp.orderId, // Transaction ID. Required.
'name': vm.orderItems[i].itemName, // Product name. Required.
'sku': '0', // SKU/code.
'category': vm.orderItems[i].itemParentCategoryName, // Category or variation.
'price': vm.orderItems[i].itemPrice,// Unit price.
'quantity': vm.orderItems[i].itemQuantity // Quantity.
});
ga('ecommerce:send');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.