【问题标题】:Angulartics: Google Analytics track full URI including anchorAngulartics:谷歌分析跟踪完整的 URI,包括锚点
【发布时间】:2017-09-21 06:36:24
【问题描述】:

我正在使用 Angulartics 和 Angulartics Google Analytics [1] 来跟踪 Angular 页面中的用户流。跟踪事件效果很好。跟踪页面浏览量也是自动的并且有效。 但是在 Google Analytics(分析)仪表板中,我看不到网址的锚点部分。

跟踪请求如下所示:

https://www.google-analytics.com/collect?
v=1&_v=j51&a=333486222&t=screenview&_s=7&
cd=%2Findex.html%23%2Fsign-in&
dl=http%3A%2F%2Flocalhost%2Findex.html&
ul=de&de=UTF-8&
dt=Treat&
sd=24-bit&sr=1918x941&
vp=1918x845&je=0&
fl=25.0%20r0&an=Treats&_u=SACAAMABO~&jid=&
gjid=&cid=1883662174.1492999789&
uid=Mark-user&tid=UA-9675XXXX-1&z=124537179

注意 cd=%2Findex.html%23%2Fsign-in 如何包含 URI 的 #sign-in 部分, 但重要的dl=http%3A%2F%2Flocalhost%2Findex.html 没有。

我的 app.js 看起来像这样:

... }).config(function ($analyticsProvider) {
$analyticsProvider.firstPageview(true); /*Records pages that don't use $state or $route*/
$analyticsProvider.withAutoBase(true);  /*Records full path*/
$analyticsProvider.virtualPageviews(true);
});
;

如何在不借助手动触发代码的情况下使用 Angulartics 跟踪包括浏览量锚点在内的完整 URI?

[1]https://github.com/angulartics/angulartics-google-analytics

[2]https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#location

【问题讨论】:

标签: cordova angular google-analytics


【解决方案1】:

我确实通过在 stateChangeSuccess 事件处理程序中禁用内置页面视图和跟踪来解决它,如下所示:

angular.module('starter', ['ionic', ... ,'angulartics',
    'angulartics.google.analytics',
    'angulartics.google.analytics.cordova','angulartics.mixpanel'])

.run(function($rootScope, $state, $analytics, $location){
  $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){

    // we do not use Angulartics virtual pageviews, instead we track them "manually" here because of
    // https://github.com/angulartics/angulartics/issues/550
    // also we track pageviews as events with the pageview path as event name to use the low cost plan of https://mixpanel.com/pricing/

    var currentPath =  $location.path();
    $analytics.pageTrack(currentPath);
    $analytics.eventTrack(currentPath, {category: 'pageview', label: 'pageview'});
  });
});

重点是用location.path 调用$analytics.pageTrack。 效果很好!我还在项目网站上报告了一个错误。

【讨论】:

猜你喜欢
  • 2016-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 2013-09-18
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多