如何在angulardart Web应用程序上设置分析?我看过Tracking Google Analytics Page Views with Angular.js,但在angulardart中没有$ scope。我使用ng-view,所以我猜我需要以某种方式将位置推送到ga变量,很可能是在RouteInitializer实现中?也许在ngRoute部分?我不确定。提前谢谢。
修改
JS:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX', 'auto');
ga('send', 'pageview');
window.addEventListener('popstate', function(event) {
ga('send', 'pageview');
});
</script>
ROUTER:
void myRouteInitializer(Router router, RouteViewFactory views) {
views.configure({
'home': ngRoute(
path: '/',
enter: views('views/home.html')),
'challenge': ngRoute(
path: '/challenge/:challengeId',
enter: views('views/view_challenge.html')),
'completed': ngRoute(
path: '/completed',
enter: views('views/completed.html')),
'404': ngRoute(
defaultRoute: true,
enter: (RouteEnterEvent e) => router.go('home', {}, replace: true))
});
答案 0 :(得分:3)
如果使用pushState完成路由,则应该可以只调用
ga('send', 'pageview');
地址栏中已显示read the correct URL,即使它不是真正的页面加载。所以从理论上讲,这应该为你做的一切:
window.addEventListener('popstate', function(event) {
ga('send', 'pageview');
});