简体   繁体   English

为什么 gtag 事件没有出现在 Google Analytics(分析)中?

[英]why the gtag event doesn't appear in Google Analytics?

my script like this:我的脚本是这样的:

<html>
<head>

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

      gtag('config', 'UA-xxxxxxxx-1');

      console.log('test');
      console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' }));
    </script>

</head>

<body>
    ...
    <a onclick="gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' });" class="test" href="...">
        <div class="text">test</div>
    </a>
    ...
</body>

</html>

The console.log of console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script> console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script> console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script> is undefined console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script> undefined

after I clicked on the test button, I tried to check on google analytics.单击测试按钮后,我尝试检查谷歌分析。 the result like this:结果是这样的:

在此处输入图像描述

there are seen total events = 0总事件数 = 0

how could this happen?怎么会这样? Is the code writing process wrong?代码编写过程是否错误?

You need to look at the real-time reports, for other views, the data could take up to 24-48 hours:您需要查看实时报告,对于其他视图,数据可能需要长达 24-48 小时: 在此处输入图像描述

The code/implementation provided works fine as-is, make sure you don't have any ad/tracking blockers:提供的代码/实现可以正常工作,请确保您没有任何广告/跟踪拦截器: 在此处输入图像描述 在此处输入图像描述

gtag.js event tracking syntax is the following: gtag.js 事件跟踪语法如下:

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

ref:https://developers.google.com/analytics/devguides/collection/gtagjs/events参考:https://developers.google.com/analytics/devguides/collection/gtagjs/events
event_label and value are optional. event_label 和 value 是可选的。
as per @Michele Pisani comment event_action is not a valid parameter根据@Michele Pisani 评论 event_action 不是有效参数

The following should work for your link以下应该适用于您的链接

<a onclick="gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_label':'Live365BroadcastLaunch-ListenLive' });" class="test" href="...">

Sometimes when a link loads a new page in the same browser window, it happens before the event hit can be sent and tracked by GA.有时,当链接在同一浏览器 window 中加载新页面时,它发生在 GA 可以发送和跟踪事件命中之前。 In these instances adding target="_blank" to the link can help在这些情况下,将 target="_blank" 添加到链接会有所帮助

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

相关问题 Google Analytics(分析)(gtag.js):产品列表名称未显示,但其他字段显示 - Google Analytics (gtag.js): Product List Name doesn't appear but other fields do 使用 gtag 和条件/触发器进行 Google Analytics 点击事件跟踪? - Google analytics click event tracking using gtag and conditional/triggers? Google Analytics(分析)点击事件无效 - Google Analytics click event doesn't work 无法使onclick事件显示在Google Analytics(分析)中 - Can't get onclick event to appear in Google Analytics gtag 谷歌分析 cookie 过期 - gtag Google Analytics cookie expiration 谷歌分析 (GTAG) 和 javaScript 问题 - Google Analytics (GTAG) and javaScript problems Google Analytics 事件跟踪不会跟踪两次或更多次 - Google Analytics Event Tracking doesn't track twice or more 使用GTAG事件将下拉列表中的选定项目发送到Google Analytics(分析) - Send the Selected Item From Drop Down List To Google Analytics With a GTAG Event 重新加载页面之前触发的Google Analytics(分析)gtag事件在iPhone上不起作用 - Google Analytics gtag event triggered before page reload, does not work on iPhone Google Analytics gtag 增强型电子商务添加到购物车事件无法识别产品信息 - Google Analytics gtag enhanced ecommerce add to cart event not recognizing product information
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM