简体   繁体   English

Google Analytics gtag 增强型电子商务添加到购物车事件无法识别产品信息

[英]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 &amp; 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, &gtm: "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.

相关问题 Google Analytics(分析)增强型电子商务(通用分析):添加到购物车中的产品的详细信息不会随添加到购物车事件一起发送 - Google Analytics Enhanced Ecommerce (Universal Analytics): Details of a product added to the cart are not sent with the add to cart event analytics.js增强型电子商务添加到购物车不起作用 - analytics.js Enhanced ECommerce add to cart not working 跟踪目录产品展示次数 - 增强型电子商务Google Analytics - Tracking catalog product impressions - Enhanced Ecommerce Google Analytics 电子商务与Google Analytics(分析)增强型电子商务的区别 - Differences of ecommerce and enhanced ecommerce of Google Analytics Google Analytics(分析)电子商务如何增加产品成本 - Google Analytics ecommerce How to add product costs Google Analytics(分析)增强型电子商务点击不起作用? - Google Analytics Enhanced Ecommerce Clicks not working? 如何指定产品添加到购物车的“列表”? 增强型电子商务 - How to specify what “list” the product was added to cart from? Enhanced Ecommerce Google Analytics(分析)增强型电子商务将不会记录购物车活动 - Google Analytics Enchanced eCommerce will not record cart activity 将产品信息添加到购物车 - Add product information to cart Google Analytics(分析)事件+电子商务跟踪=&gt;事件丢失 - Google Analytics Event + eCommerce tracking => events lost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM