gpt4 book ai didi

google-analytics - AngularDart和Google Analytics(分析)

转载 作者:行者123 更新时间:2023-12-03 16:03:57 26 4
gpt4 key购买 nike

如何在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>

路由器:

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

最佳答案

如果您的路由是通过pushState完成的,则您应该可以调用

ga('send', 'pageview');

即使它不是真正的页面加载,也已经在地址栏中显示了 read the correct URL。因此,从理论上讲,这应该为您做所有事情:

window.addEventListener('popstate', function(event) {
ga('send', 'pageview');
});

关于google-analytics - AngularDart和Google Analytics(分析),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26092027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com