1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.