将 Google 分析与 shiny.router 结合使用
Using Google Analytics with shiny.router
我正在尝试将 Google Analytics 与我的 Shiny 应用程序一起使用,我将其发布在 shyniapps.io。
但在我的应用程序中我使用 shiny.router
,因此它创建的页面带有 #!
符号并且某些页面的所有路径看起来像 myapp/#!/page
。
Google Analytics 显示此成绩与 myapp/
一样。
shinyapps 还在 myapp
和 #!
之间创建以 _w_
符号开头的路径(我认为这是会话代码或其他)。所以最后所有路径看起来像 myapp/_w_00000000/#!/page
其中 0
是随机十六进制数 (0-f
).
我只使用标准 Google 分析脚本:
<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-000000000-0', 'auto');
ga('send', 'pageview');
</script>
那么,我如何发送到 Google Analytics 正常样式的路径 myapp/page
而不是显示 myapp/_w_00000000/#!/page
默认情况下,Google Analytics 使用 location.pathname
定义单独的页面。您可以通过传递 location.href
作为标识参数来覆盖它:
...
ga('send', 'pageview', document.location.href);
我正在尝试将 Google Analytics 与我的 Shiny 应用程序一起使用,我将其发布在 shyniapps.io。
但在我的应用程序中我使用 shiny.router
,因此它创建的页面带有 #!
符号并且某些页面的所有路径看起来像 myapp/#!/page
。
Google Analytics 显示此成绩与 myapp/
一样。
shinyapps 还在 myapp
和 #!
之间创建以 _w_
符号开头的路径(我认为这是会话代码或其他)。所以最后所有路径看起来像 myapp/_w_00000000/#!/page
其中 0
是随机十六进制数 (0-f
).
我只使用标准 Google 分析脚本:
<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-000000000-0', 'auto');
ga('send', 'pageview');
</script>
那么,我如何发送到 Google Analytics 正常样式的路径 myapp/page
而不是显示 myapp/_w_00000000/#!/page
默认情况下,Google Analytics 使用 location.pathname
定义单独的页面。您可以通过传递 location.href
作为标识参数来覆盖它:
...
ga('send', 'pageview', document.location.href);