UI的路由器上的谷歌分析状态变化获取当前路径路由、路径、器上、状态

2023-09-13 02:40:24 作者:古风大全

我想获得国家的路径发送到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());}); 
Nest Wi Fi路由器app Google Nest Wi Fi路由器app第二代最新版预约 v1.0 嗨客手机下载站

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());
});