简体   繁体   English

将 Google Analytics 与 shiny.router 一起使用

[英]Using Google Analytics with shiny.router

I'm trying to use Google Analytics with my Shiny app and I published it on shyniapps.io.我正在尝试将 Google Analytics 与我的 Shiny 应用程序一起使用,并将其发布在 shyniapps.io 上。

But in my app I use shiny.router , so it creates pages with #!但是在我的应用程序中,我使用shiny.router ,因此它使用#! symbols and all path of some page looks like myapp/#!/page .某些页面的符号和所有路径看起来像myapp/#!/page Google Analytics displays this pas just as myapp/ . Google Analytics 将这个过程显示为myapp/ Also shinyapps creates path between myapp and #!此外,shinyapps 在myapp#!之间创建路径which starts with _w_ symbols (I think it's session code or something else).它以_w_符号开头(我认为它是 session 代码或其他代码)。 So in the end all path looks like myapp/_w_00000000/#!/page where 0 is random hex numbers ( 0-f ).所以最后所有路径看起来像myapp/_w_00000000/#!/page ,其中0是随机十六进制数字( 0-f )。

I use just a standard Google Analytics script:我只使用标准的 Google Analytics 脚本:

<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>

So, how I could send to Google Analytics normal styled paths myapp/page instead displayed myapp/_w_00000000/#!/page所以,我怎么能发送到谷歌分析正常样式的路径myapp/page而不是显示myapp/_w_00000000/#!/page

by default, Google Analytics uses location.pathname to define separate pages.默认情况下,Google Analytics 使用location.pathname来定义单独的页面。 you might override this by passing location.href as an identification parameter:您可以通过将location.href作为标识参数来覆盖它:

...
ga('send', 'pageview', document.location.href);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM