簡體   English   中英

無法使用 React 將電子商務數據發送到 Google Analytics

[英]Impossible to send ecommerce data to Google Analytics with React

我無法使用 React 將增強的電子商務跟蹤數據發送到谷歌分析。

我把這段代碼放在我的 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();

我正在使用谷歌調試器,一切似乎都很好。 但我的谷歌分析沒有收到任何信息。 當我使用舊的電子商務插件時,它工作正常,但沒有增強電子商務。 我嘗試不使用帶有 js 本機代碼的 ReactGA 庫,但結果相同。

知道我的問題是什么嗎?

試試它對我的工作並使用文檔

 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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM