Reputation: 3628
I'm using Google Analytics for the first time. I've copied the supplied script tags into my page's header.
I can visit the page and I see one visitor in real time reports. In addition to recording the number of visitors to the page, I also want to report an event when a user clicks on a particular button on the page.
I have some jQuery to handle the click:
$("#new-preview").click(function(){
new_preview()
ga('send', 'event', 'preview', 'new', 'v1');
console.log('Click!')
})
I can see that the function runs because the expected text is logged to the console. However, no events are recorded in Google Analytics (Reports -> Real-Time -> Events). I following the instructions provided by Google here. I think I'm following them correctly.
Why isn't the event being recorded? What have I misunderstood?
Upvotes: 1
Views: 68
Reputation: 3847
ga(...)
calls works with ~old~ analytics.js snippet. You're probably using the new gtag.js snippet. In that case you'll need another call to track events, something like
gtag('event', 'new', {
'event_category': 'preview',
'event_label': 'v11'
});
Check the docs for analytics.js here and for gtag.js here
Upvotes: 1