Angulartics:Google Analytics跟踪包含锚点的完整URI

时间:2017-04-24 14:13:36

标签: cordova angular google-analytics

我正在使用Angulartics和Angulartics Google Analytics [1]来跟踪角度页面中的用户流量。跟踪事件运作良好。跟踪网页浏览也是自动且有效的。 但是,在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如何包含#sign-in部分URI, 但重要的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);
});
;

如何跟踪完整的URI,包括使用Angulartics进行综合浏览量的锚点,而无需使用手动触发器代码?

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

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

1 个答案:

答案 0 :(得分:0)

我通过在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'});
  });
});

关键是与$analytics.pageTrack联系location.path。 效果很好!我还在项目网站上报告了一个错误。