handle urls with hash # with google analytics

家住魔仙堡 提交于 2019-12-04 13:45:45

You need to parse the parameters after # and send the data by using _trackPageview in order to see them on your pages report.

and here is how to do it,

 var params = {},
     queryString = location.hash.substring(1), 
     regex = /([^&=]+)=([^&]*)/g, 
     m; 
 while (m = regex.exec(queryString)) { 
     params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
 }
 _gaq.push(['_trackPageview', queryString]);

Use $window dependency and call on route change.

Also use GA 'set' to ensure routes are picked up for Google realtime analytics.

$scope.$on('$routeChangeSuccess', function() {
    $window.ga('set', 'page', $location.url());
    $window.ga('send', 'pageview');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!