On my react PWA I want to track conversions in Google Adwords after, for example, sending form data. I already use the react-ga module to track pageviews which uses a UA-xxxxxx number. Now I have an Adwords number AW-xxxxxx and I can't seem to find a working example with that. Which react module can I use to send those Events to my AW-xxxxxx number?
I already took a look at really small and seemingly incomplete Adwords modules for react, but they do not include Event tracking or don't take AW-xxxxx numbers, only GTM-xxxxx.
This is the code I need to implement:
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-xxxxx"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-xxxxxx');
</script>
And for the Event:
<script>
gtag('event', 'conversion', {'send_to': 'AW-xxxxx/XXXXXX'});
</script>
I STRUGGLED with implementing the response above. Here is a MUCH EASIER way to get this accomplished.
<!-- ADDED TO TRACK GOOGLE CONVERSION -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
</script>
componentDidMount () {
window.gtag('config', 'AW-XXXXXXXXXX');
window.gtag('event', 'conversion', {'send_to': 'AW-XXXXXXXXXX/YYYYYYYYY-ZZZZZZZZZZ'});
}
You can add <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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With