Analytics
3.7K members online now
3.7K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply
Highlighted

Google Analytics Custom Event Not Working

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have a goal in GA, and a matching onclick event on a button as follows...

 

<a target="_blank" href="http://amzn.to/2xr9Kgx" class="btn_bmi blue white" onclick="ga('send', 'event', 'BuyNow', 'click');">Buy Now</a>

 

When I click the link I should see the event fire in GA > REAL TIME > Events. However, nothing appears.

 

I don't get any console errors so the onclick event seems fine.

 

I thought maybe the "target="_blank"" was not allowing the JS to finish firing, but the onclick page remains in the browser so I don;t think that's the issue. Just in case, tho, I tested with just a regular link going to another page in the site. Still no event in GA.

 

If you want to see a sample page, hit this...

http://www.bigmouthinc.com/products/giant-donut-pool-float/  

 

The onclick event is attached to the blue "Buy Now" button.

 

Thanks for any suggestions!

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Barry B
November

Re: Google Analytics Custom Event Not Working

Participant ✭ ☆ ☆
# 2
Participant ✭ ☆ ☆

I checked your site and the issue is that you're using the newest version of the GA tracking script (gtag.js), but sending the event using the old syntax for analytics.js.

 

Instead of 

ga('send', 'event', 'BuyNow', 'click');

 

it should be 

gtag('event', 'click', {
 
'event_category': 'BuyNow'
});

 

This page describes the difference in event syntax in more detail: https://developers.google.com/analytics/devguides/collection/gtagjs/migration#track_events

 

 

 

 

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Barry B
November

Re: Google Analytics Custom Event Not Working

Participant ✭ ☆ ☆
# 2
Participant ✭ ☆ ☆

I checked your site and the issue is that you're using the newest version of the GA tracking script (gtag.js), but sending the event using the old syntax for analytics.js.

 

Instead of 

ga('send', 'event', 'BuyNow', 'click');

 

it should be 

gtag('event', 'click', {
 
'event_category': 'BuyNow'
});

 

This page describes the difference in event syntax in more detail: https://developers.google.com/analytics/devguides/collection/gtagjs/migration#track_events

 

 

 

 

Google Analytics Custom Event Not Working

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks Ana! Working now. I knew the tracking script was different, but no console errors made it seem like it should be working. However, after I posted I ran the GA debugger extension and could see an issue.

Google Analytics Custom Event Not Working

Participant ✭ ☆ ☆
# 4
Participant ✭ ☆ ☆

Great to hear, thank you for coming back with an update.

Google Analytics Custom Event Not Working

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

it work for me. Thank you so much. Smiley Happy