I'm trying to send an analytics event on a button click and it's not working. When I look in Analytics reports in Realtime > Events section, I can see one active user (the site isn't public yet, so I'm the only user) but I see no events for active users and no events in the last 30 min. In the Events per minute graph I have a flat line also. Active users and page views work just fine.
I have this JS in my page header:
<#-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-1');
</script>
and this event on the button:
onclick="javascript:ga('send', 'event', 'buttons', 'click', 'Test 123');"
and it doesn't work.
Even if I call the ga
function from the JS console, there is no event recorded. The function returns undefined and nothing goes on the network. The ga
function doesn't seem to be doing anything. No errors either.
What am I doing wrong?