Worpdress上的Google Analytics(分析)事件跟踪

Worpdress上的Google Analytics(分析)事件跟踪

问题描述:

当我单击特定菜单项时,我正在尝试发送事件.我的标头脚本如下:

I am trying to send an Event when clicked on a specific menu item. My header scripts are as follows:

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

  gtag('config', 'UA-124755880-1');
</script>

<!-- Custom Google Analytics click event -->
<script>
jQuery(document).ready(function($){

    function handleOutboundLinkClicks(event) {
       console.log(event.target.href);
       ga('send', 'event', {
        eventCategory: 'Outbound Link',
        eventAction: 'click',
        eventLabel: 'Book Now'
       });
    }

  $('.book-link a').click(function(event){
      console.log('click');
      handleOutboundLinkClicks(event)      
  });
});

</script>

所有控制台日志均按预期方式工作,该站点上没有错误. 我只是在Google Analytics(分析)仪表板上看不到该事件.不在报表中,也不在实时事件中.

All console logs work as supposed, no errors on the site. I just can't see the event on my Google Analytics dashboard. Not in reports and not in the Real-time events.

链接具有target="_blank"属性,因此我尝试使用transport: 'beacon'和不使用transport: 'beacon'.到目前为止没有.

The link has target="_blank" attribute so I tried with and without transport: 'beacon'. Nothing so far.

你知道我在做什么错吗?

Do you have any idea what I am doing wrong?

谢谢

您正在使用gtag()方法初始化GA,因此您应该使用gtag()函数调用来发送事件:

You are initializing GA using the gtag() method so you should be using the gtag() function call for sending events:

gtag('event', 'click', { 'event_category': 'Outbound Link','event_label': 'Book Now'
 });

1)检查呼叫是否可以单独运行,没有点击事件.您可以通过将gtag调用复制/粘贴到控制台中来测试脚本,并查看它是否建立了连接或是否提供了错误.如果连接正常,则在手动调用该函数时,将在浏览器devtools的网络"选项卡中看到一个请求.

1) Check if call works on its own, without a click event. You can test the script by copy/pasting the gtag call into the console and see if it makes the connection or if it gives an error. If the connection works you will see a request in the "network" tab of the browsers devtools when manually calling the function.

2)确认您的浏览器可以连接到GA.您可以检查devtools中的网络"选项卡,以查看是否已进行所有对分析的调用或是否被阻止.如果您以隐私/内容阻止模式运行广告拦截器或运行浏览器,则这些跟踪器请求可能会停止.默认情况下,根据您使用的浏览器的不同,GA可能已被阻止.

2) Verify your browser can connect to GA. You can check the "network" tab in devtools to see if all the calls to analytics are being made or if they are blocked. If your running an ad-blocker or running the browser in a privacy/content blocking mode these tracker requests could be getting stopped. Depending on the browser you are using GA may already be blocked by default.

3)验证分析可以看到您的请求.检查分析是否在实时跟踪中看到您的操作.首先查找初始综合浏览量,如果该方法无效,请确保使用未经过滤的视图进行测试.

3) Verify analytics can see your requests. Check if analytics is seeing your actions in Realtime tracking. Look for the initial pageview first, if that isn't working make sure your testing with an unfiltered view.