gpt4 book ai didi

reactjs - 无法使用 React 将电子商务数据发送到 Google Analytics

转载 作者:行者123 更新时间:2023-12-05 07:07:34 24 4
gpt4 key购买 nike

我在使用 React 将增强型电子商务跟踪数据发送到 Google Analytics 时遇到问题。

我将这段代码放在我的 index.js 中只是为了测试:

ReactGA.initialize('UA-MY-ID-7', {
debug: true,
});
ReactGA.plugin.require('ec');


ReactGA.plugin.execute('ec', 'setAction', 'detail', {
step: 1,
});

ReactGA.plugin.execute('ec', 'setAction', {
id: '1',
affiliation: 'Allocab',
revenue: 30, // Grand Total.
shipping: '0', // Shipping.
tax: 32, // Tax.
currency: 'EUR',
coupon: 'POMOCODE',
});

ReactGA.event({
category: 'Booker-ecommerce',
action: 'New transaction',
});

ReactGA.plugin.execute('ec', 'addPromo', 'promo_click', {
name: 'PROMOCODE',
});

ReactGA.event({
category: 'Booker-ecommerce',
action: 'New discount code',
});

ReactGA.plugin.execute('ec', 'addProduct', 'add', {
name: 'PRODUCT', // Product name. Required.
price: 30, // Unit price.
quantity: 1, // Quantity.
currency: 'EUR',
category: 'CATEGORY',
});

ReactGA.event({
category: 'Booker-ecommerce',
action: 'Add product',
});
ReactGA.plugin.execute('ec', 'setAction', 'add', {
step: 2,
});

ReactGA.plugin.execute('ec', 'addProduct', 'checkout', {
name: 'PRODUCT', // Product name. Required.
price: 30, // Unit price.
quantity: 1, // Quantity.
currency: 'EUR',
category: 'CATEGORY',
});

ReactGA.event({
category: 'Booker-ecommerce',
action: 'Start checkout',
});

ReactGA.plugin.execute('ec', 'setAction', 'checkout', {
step: 3,
option: 'Visa',
});

ReactGA.plugin.execute('ec', 'addProduct', 'purchase', {
name: 'PRODUCT', // Product name. Required.
price: 30, // Unit price.
quantity: 1, // Quantity.
currency: 'EUR',
category: 'CATEGORY',
coupon: 'PROMOCODE',
});

ReactGA.event({
category: 'Booker-ecommerce',
action: 'Purchase product',
});

ReactGA.plugin.execute('ec', 'setAction', 'purchase', {
step: 4,
option: 'Visa',
});

ReactGA.pageview();

我正在使用 Google 调试器,一切似乎都正常。但我的 Google Analytics(分析)中没有收到任何信息。当我使用旧的电子商务插件时,它工作正常,但增强型电子商务没有任何作用。我尝试在没有 ReactGA 库的情况下使用 js native 代码,但结果相同。

知道我的问题是什么吗?

最佳答案

试试这个对我有用并使用 documentation

 ReactGA.plugin.require('ec');


for (let i = 0; i < data.orderItems.length; i++) {
ReactGA.plugin.execute('ec', 'addProduct', {
id: data.orderItems[i].id,
name: data.orderItems[i].product.name,
brand: data.orderItems[i].product.brand,
category: data.orderItems[i].product.categories,
variant: data.orderItems[i].product.product_type_name,
sku: data.orderItems[i].product_id,
price: data.orderItems[i].cost,
quantity: data.orderItems[i].quantity,
currency: "USD",
});
}

ReactGA.plugin.execute('ec', 'setAction', 'purchase', {
id: data.order_id,
affiliation: storeName,
revenue: data.total_cost,
shipping: data.delivery_cost,
currency: "USD",
tax: data.tax
});
ReactGA.pageview('/orderDetails');
ReactGA.plugin.execute('ec', 'clear');

关于reactjs - 无法使用 React 将电子商务数据发送到 Google Analytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62086820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com