user3574603
user3574603

Reputation: 3628

JS: Event not showing in Google Analytics

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

Answers (1)

Дмитро Булах
Дмитро Булах

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

Related Questions