本文介绍了使用gtag.js在Google Analytics(分析)中进行事件跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习Google Analytics(分析).我在Angular中有单页应用程序.应用程序中有一个登录按钮.我想跟踪使用GA登录的用户数.所以我要做的是我在GA中创建了一个属性,并获得了跟踪ID.然后,我在索引页面后添加了以下脚本.

现在,如果登录成功,我将添加ga().但是不幸的是,当我成功登录后,我无法在REAL-TIME-> Events-> bottom most表中列出的Event Category和Event Action中找到任何数据.我不知道为什么吗?

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

  gtag('config', 'UA-XXXXXXXX-X');
</script> 

 $http({enter code here
          method: 'POST',
          'async': true,
          'cache': false,
          'global': false,
          url: //the  correct url,
          isStaySignIn: isStaySignIn,
          isIdamOn: true,
        }).success(function(data, status, headers) {
          $rootScope.Loading = "Loading";
          deferred.resolve({
            data: data,
            headers: headers
          });
          
          ga('send', {
            hitType: 'event',
            eventCategory: 'MODE',
            eventAction: 'IDAM',
            eventLabel: 'Login using Jio ID'
          });
        }) 

解决方案

您应该使用gtag.js发送GA事件,因为这是您实施GA的方法,而不是analytics.js的ga(). /p>

发送事件的模式是:

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

更新的代码段:

 $http({enter code here
          method: 'POST',
          'async': true,
          'cache': false,
          'global': false,
          url: //the  correct url,
          isStaySignIn: isStaySignIn,
          isIdamOn: true,
        }).success(function(data, status, headers) {
          $rootScope.Loading = "Loading";
          deferred.resolve({
            data: data,
            headers: headers
          });
          
          //send login event using gtag.js
          gtag('event', 'IDAM', {
            'event_category': 'MODE',
            'event_label':'Login using Jio ID',
          });

        }) 

I have recently started learning Google Analytics(GA). I have single page application in Angular. There is a login button in the application. I wanted to track how many users are logged in using GA. So what i did is i created a property in GA and got the tracking id . Then i added the following script just after the in index page.

Now i added the ga() if the login is successful . But unfortunately when i successfully login , i can't find any data in Event Category and Event Action listed in REAL-TIME->Events->bottom most table . I am not able to figure out why?

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

  gtag('config', 'UA-XXXXXXXX-X');
</script>

$http({enter code here
          method: 'POST',
          'async': true,
          'cache': false,
          'global': false,
          url: //the  correct url,
          isStaySignIn: isStaySignIn,
          isIdamOn: true,
        }).success(function(data, status, headers) {
          $rootScope.Loading = "Loading";
          deferred.resolve({
            data: data,
            headers: headers
          });
          
          ga('send', {
            hitType: 'event',
            eventCategory: 'MODE',
            eventAction: 'IDAM',
            eventLabel: 'Login using Jio ID'
          });
        })

解决方案

You should be using gtag.js to send GA events, since that's your method of implementation of GA, not ga() as that's for analytics.js.

The pattern to send an event is:

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

Updated snippet:

$http({enter code here
          method: 'POST',
          'async': true,
          'cache': false,
          'global': false,
          url: //the  correct url,
          isStaySignIn: isStaySignIn,
          isIdamOn: true,
        }).success(function(data, status, headers) {
          $rootScope.Loading = "Loading";
          deferred.resolve({
            data: data,
            headers: headers
          });
          
          //send login event using gtag.js
          gtag('event', 'IDAM', {
            'event_category': 'MODE',
            'event_label':'Login using Jio ID',
          });

        })

这篇关于使用gtag.js在Google Analytics(分析)中进行事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 01:10