来自 HTML OnClick 的 gtag 调用未达到 GA

gtag call from HTML OnClick does not reach GA

意识到我不是在使用旧的 analytics.js,而是在使用 gatg.js,这让我自己摸不着头脑。 下面的调用没有被触发,所以对于 Google documentation for ga to gtag Migration 它不会那样工作:

<a href="https://example.com" 
    onclick="gtag('event', {
        'event_category': 'Downloads', 
        'event_action': 'download', 
        'event_label': 'softwarename', 
        'value': '1'});">
Download</a>

关于必须如何格式化 gtag 调用以使其可行的任何建议?

gtag.js documentaion 跌跌撞撞之后,我发现必须使用另一种语法,而且确实是转换:

eventAction => event_action

不像问题中链接的迁移文档中建议的那样工作。 可行的调用将动作参数拖到最前面,如:

<a href="https://example.com" 
onclick="gtag('event', 'download', {
    'event_category': 'Downloads',  
    'event_label': 'softwarename', 
    'value': '1'});">Download</a>