我想获得国家的路径发送到Google Analytics。有一些问题。我使用的抽象状态,所以使用类似toState.url不会工作,因为它不会抢了整个网址。
我想用在$ stateChangeSuccess $ window.location.pathname的,但事实证明,成功火灾网址在浏览器更新前。这意味着,浏览量被发送1页视图为时已晚。即
单击一下:什么都不发点击联系人:发送有关网址单击服务:发送URL接触
基本上,最终的结果应该是这个样子,但与使用toState URL或路径:
$ rootScope。在$($ stateChangeStart功能(事件,toState,toParams,fromState,fromParams){ VAR路径= ???; GA(发送,浏览量,路径);});
解决方案
看起来你需要使用$位置,而不是获得新的路径:
$ rootScope。在$($ stateChangeSuccess功能(事件,toState,toParams,fromState,fromParams){ $ window.ga(发送,浏览量,$ location.path());});
I am trying to get the path of the state to send to google analytics. There are some issues. I am using abstract states, so using something like toState.url wont work as it wont grab the entire url.
I thought of using $window.location.pathname on $stateChangeSuccess, but it turns out success fires before the url is updated in the browser. This means that pageviews get sent 1 page view too late. ie.
click about: sends nothing
click contact: sends about url
click services: sends contact url
Basically the end result should look something like this, but with the toState url or pathname:
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
var path = ???;
ga('send', 'pageview', path);
});
解决方案
looks like you need to use $location instead to get the new path:
$rootScope.$on("$stateChangeSuccess", function(event, toState, toParams, fromState, fromParams) {
$window.ga('send', 'pageview', $location.path());
});
上一篇:需要帮助使用量角器中环和gettext的()量角器、中环、gettext
下一篇:验证码的问题:没有“访问控制允许来源”标头的请求的资源present甚至总是显示我在angularJS添加页眉页眉、我在、验证码、访问控制