2

I'm trying to configure google analytics for my react application. In my work I use the react-ga plugin. In all instructions they write that in the ReactGS.initialize() method, the arguments must be in the format UA-XXXXXX-XX, but for conversion, the format AW-XXXXXXXXX is needed. Code example in docs:

ReactGA.initialize('UA-000000-01');

In my case:

// initialize
App.js (main file)

useEffect(() => {
   ReactGA.initialize('AW-XXXXXXXXX');
}, [params])

// call when event is done
api.js

POST METHOD
ReactGA.ga('event', 'conversion', {'send_to': 'AW-XXXXXXXXX/xxxxxxxxxxxxxxx'})

But code below is not working. Maybe someone had a similar problem and knows how to solve it

mara1esh
  • 35
  • 1
  • 5
  • 1
    What your are referring for this `ReactGA.ga('event', 'conversion', {'send_to': 'AW-XXXXXXXXX/xxxxxxxxxxxxxxx'})`? – ravibagul91 Aug 05 '19 at 10:09
  • @ravibagul91 , I use that code in POST method. I'm tracking events on my application so when the some event is done I have to run that code. ``` axios.post('/api/request/new-request', { name, number }) .then(() => { ReactGA.ga('event', 'conversion', {'send_to': 'AW-730521646/qJ3JCJKA6KUBEK7Aq9wC'}) }) ``` – mara1esh Aug 05 '19 at 10:17
  • @ravibagul91 or did you mean something else – mara1esh Aug 05 '19 at 10:19
  • Yes I have not seen such event. So trying to understand what is {'send_to': 'AW-730521646/qJ3JCJKA6KUBEK7Aq9wC'} part. – ravibagul91 Aug 05 '19 at 10:24
  • Because once initialized your normal event is like this, `ReactGA.event({ category: 'User', action: 'Created an Account' });` – ravibagul91 Aug 05 '19 at 10:25
  • @ravibagul91 That's my fault. They track events in multi-page sites without the react-ga plugin, and I tried to combine them. If this is not the right approach, then I have no idea how to track events and pass on the parameters I need (arg: send_to). The documentation does not describe my case. Do you have any ideas how to solve my problem or where I have to looking for necessary information? – mara1esh Aug 05 '19 at 10:42
  • Try this - `ReactGA.event({ category: 'conversion', action: 'AW-730521646/qJ3JCJKA6KUBEK7Aq9wC' })` – ravibagul91 Aug 05 '19 at 10:49
  • Actually your requirement is not so clear to me. May be you need to edit post with more relavant example of what you are trying to achieve. – ravibagul91 Aug 05 '19 at 10:51
  • @ravibagul91 thanks so much. I'll try it – mara1esh Aug 05 '19 at 11:25
  • Did you ever find a solution for this? – Shane O Sullivan Sep 13 '19 at 20:26
  • Anyone find a solution for this.. To track conversion through react-ga – Wajahat Qasim Sep 24 '20 at 12:46
  • How did you solve it? – Luis Quiroga Dec 28 '21 at 06:27

1 Answers1

2

Tracking in Google Analytics and Google Ads are different. Currently, it's not possible to track directly from react-ga to Google Ads, see: https://github.com/react-ga/react-ga/issues/270

You can add Google Ads' tracking code to <script> tags directly to your index.html or use Helmet. Then you can call window.gtag.

What I'd recommend instead though, as you're already using Google Analytics with react-ga, is to use a Google Analytics Goal as a Conversion metric is Google Ads. Follow these steps:

This way you only have to worry about tracking with a single service.

thisismydesign
  • 21,553
  • 9
  • 123
  • 126