Search code examples
javascriptreactjsgoogle-analyticsreact-ga

Setup react-ga for conversion


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


Solution

  • 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.