How To Track Events With gtag.js (Google Analytics) For Conversion Tracking

Author: Kenneth ([email protected])

Published: Thursday March 4, 2021

What is Conversion Tracking?

Conversion tracking is a free tool that shows you what happens after a customer interacts with your ads — whether they purchased a product, signed up for your newsletter, called your business, or downloaded your app. When a customer completes an action that you’ve defined as valuable, these customer actions are called conversions.

Step 1:
Install Google Analytics gtag.js.

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');

Step 2:
Add an event listener to your element and send the event command. That’s it!

element.onclick = function() {
  gtag('event', 'aaa', {
    'event_category' : 'bbb',
    'event_label' : 'ccc'

You can use the steps above to set up your conversion tracking. Learn more from Google here.