简体   繁体   English

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

[英]Why is my Google Analytics callto event tracking code not tracking?

I am trying to track a call tel event when a button is clicked. 我试图跟踪单击按钮时的电话呼叫事件。 My GA code was provided from the setup wizard. 我的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>

And my button code is: 我的按钮代码是:

<!-- 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>

Vote 投票

Please up or down vote the question. 请向上或向下投票表决该问题。 Before down voting, suggest edits or leave comments? 在投反对票之前,建议编辑还是发表评论?

You have GA implemented via gtag.js, the function you used for onClick is for analytics.js, so you need to use the right functions . 您已经通过gtag.js实现了GA,用于onClick的函数用于analytics.js,因此您需要使用正确的函数 You need to do it in this format: 您需要采用以下格式:

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

so for your example: 因此,对于您的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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