reactjs - 电子商务跟踪数据未通过 react-ga 发送

标签 reactjs google-analytics

我在向谷歌发送电子商务跟踪数据时遇到问题,目前我可以正常查看页面浏览量,但它没有注册转换事件。

这是我当前的设置:

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

最佳答案

我能够通过将数据发送给 ga 以验证付款来完成这项工作

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

关于reactjs - 电子商务跟踪数据未通过 react-ga 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42804001/

相关文章:

reactjs - onClick 里面有两个参数

reactjs - Webpack Code Splitting 'Loading chunk failed' 错误文件路径错误

javascript - 使用 Webpack HtmlWebpackPlugin

javascript - 选择选项时 react 中的 <select> 标签不改变

ios - 由于重复符号错误,GoogleAnalytics 无法在 Xcode 10 beta 5 上编译

google-analytics - 当客户在某个页面上时,获得实时通知

reactjs - 从 styled-component 推断 Prop 接口(interface)

javascript - Google 广告管理系统 (DFP) 中是否会阻止分析事件?

google-analytics - 谷歌分析 : Only include traffic that has visited a particular page

jquery - 如何使用 Google Analytics 跟踪 HTML5 浏览器功能 (modernizr)?