Worpdress 上的 Google Analytics 事件跟踪 [英] Google Analytics Event Tracking on Worpdress

查看:16
本文介绍了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'.到目前为止什么都没有.

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 调用复制/粘贴到控制台来测试脚本,看看它是否建立了连接或是否出现错误.如果连接正常,您将在手动调用该函数时在浏览器开发工具的网络"选项卡中看到一个请求.

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.

这篇关于Worpdress 上的 Google Analytics 事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆