为什么我的Google Analytics(分析)号召性事件跟踪代码无法跟踪?

时间:2019-09-18 16:33:18

标签: javascript google-analytics

单击按钮时,我试图跟踪电话事件。我的GA代码是通过设置向导提供的。

<!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={{site.google_analytics_tracking_id}}"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
          gtag('config', '{{site.google_analytics_tracking_id}}');
    </script>

我的按钮代码是:

<!-- Banner -->
<section id="banner">
    <div class="inner">
        <header>
            <h2>{{ site.title }}</h2>
            <figure>
                <picture class="image logo">
                    <span class="icon logo fa-balance-scale"></span>
                </picture>
                <figcaption><small>Serving: {{ site.location }}</small></figcaption>
            </figure>
        </header>
        <p><strong>We Work Hard To Protect Your Rights!</strong></p>
        <footer>
            <ul class="buttons stacked">
                <button class="button fit">Call: <a href="tel:{{site.tel}}" onClick=”ga('send', 'event', 'Calls', 'clicked', 'Contact Office', 1);”>{{site.tel}}</a></button>
            </ul>
        </footer>
    </div>
</section>

投票

请上下投票表决该问题。在投反对票之前,建议编辑还是发表评论?

1 个答案:

答案 0 :(得分:1)

您已经通过gtag.js实现了GA,用于onClick的功能是analytics.js,因此您需要使用the right functions。 您需要使用以下格式:

gtag('event', <action>, {
  'event_category': <category>,
  'event_label': <label>,
  'value': <value>
});

因此,您的示例:

gtag('event', 'clicked', {
  'event_category': 'Calls',
  'event_label': 'Contact Office',
  'value': 1
});
相关问题