NooBskie NooBskie -4 years ago 163
React JSX Question

eCommerce tracking data not being sent with react-ga

I'm having trouble sending eCommerce tracking data to google currently I am able to see page views fine but it is not registering the events for conversions.

Here is my current setup:

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


I've added the code below for testing eCommerce data but nothing is being sent what am I doing wrong here?

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

Answer Source

I was able to get this working by dispatching the data to ga on a verified payment

  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');
      }
    });
  }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download