Tracking an event to Google Analytics using gtag by Jason Ramsey on Thursday, December 17th 2020

I wanted to start adding some event tracking to and I was orginally just going to save to a local database but choose to use google instead. I had a bit of a learning curve to the fact that gtag and ga are two seperate methods. If you are using - you'll want to use gtag() instead of ga().

gtag.js vs analytics.js

The Google Analytics examples I found online first all used GA, so I thought I needed to use GA as well.

 ga('send', 'event', ACTION, CATEGORY, LABEL);

What was confusing is the fact ga() did not throw an errors, however no events were fired.

 gtag('event', ACTION, {'event_category' : CATEGORY, 'event_label' : LABEL});

Once I moved to gtag('event') things showed up in the RealTime section of Google Analytics.

Hopefully this helps someone else!

Back to List Next Entry