简体   繁体   中英

Google Analytics event not firing

My Google Analytics event isn't firing on my webpage. Below is my code. It opens the url in a new tab just fine, and there are no errors in the console. But when I go to Google Analytics -> Real-Time -> Events my goal has no activity. It's using Universal Analytics because when I view page source I see analytics.js.

<a href="https://myurl.com" onclick="ga('send', 'MyEvent', 'Click');" target="_blank">under construction </a></p>

If it helps, my Goal setup is:

Category - MyEvent
Action - Click

Use the Event value as the Goal Value for the conversion - Yes

New version of analytics has a different syntax: Replace this line

ga('send', 'MyEvent', 'Click');

With

gtag('event', 'click', {'event_category' : 'MyEvent', 'event_action' : 'Click', 'event_label' : 'Label is optional'});"

you are missing the hit type property.

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

Full documentation is here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM