电子商务跟踪数据未与react-ga一起发送

时间:2017-03-15 08:00:18

标签: reactjs google-analytics

我在向Google发送电子商务跟踪数据时遇到问题我可以看到网页浏览量不错,但是没有注册转化事件。

这是我目前的设置:

// Application entry point
import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-redux';
import {Router, browserHistory} from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';

import ReactGA from 'react-ga';
ReactGA.initialize('UA-myID-2');
ReactGA.plugin.require('ecommerce');

// Google Analytics
function fireTracking() {
  ReactGA.pageview(location.pathname, location.pathname);
  ReactGA.plugin.execute('ecommerce', 'addTransaction', {
    id: 'jd38je31j',
    revenue: '3.50'
  });
}

render (
  <Provider store={store}>
    <Router history={history} routes={routes} onUpdate={() => window.scrollTo(0, 0), fireTracking} />
  </Provider>, document.getElementById('app')
);

我已经添加了以下代码来测试电子商务数据,但没有发送任何内容我在这里做错了什么?

ReactGA.plugin.execute('ecommerce', 'addTransaction', {
  id: 'jd38je31j',
  revenue: '3.50'
});

2 个答案:

答案 0 :(得分:2)

我能够通过将数据发送到经过验证的付款

来实现这一目标
  verifyAlipay() {
    const {dispatch} = this.props;
    $.ajax({
      type: 'GET',
      url: `${API_URL}/orders/${this.props.location.query.out_trade_no}/complete`
    }).then(resp => {
      if (resp.result == 'success') {
        dispatch(fetchCart());
        ReactGA.plugin.execute('ecommerce', 'addTransaction', {
          'id': '1234',                     // Transaction ID. Required.
          'name': 'test checkout',          // Product name. Required.
          'sku': 'DD23444',                 // SKU/code.
          'category': 'Party Toys',         // Category or variation.
          'price': '11.99',                 // Unit price.
          'quantity': '1'                   // Quantity.
        });
        ReactGA.plugin.execute('ecommerce', 'send');
        ReactGA.plugin.execute('ecommerce', 'clear');
      }
    });
  }

答案 1 :(得分:1)

导入前无法使用模块。首先,您需要使用ReactGA.plugin.require()

导入插件

https://github.com/react-ga/react-ga#reactgapluginrequirename-options