Google 闪亮仪表板应用分析
Google Analytics for Shiny Dashboard App
我有一个整理得很好的 R shiny (shinydashboard) 应用程序,它 运行 在服务器上。我希望能够跟踪它的使用情况,并且知道 google 分析是一个很好的解决方案。但是我 运行 遇到了设置问题。
我已尝试按照此处描述的说明进行操作 https://shiny.rstudio.com/articles/google-analytics.html
他们建议创建一个 google-analytics.js 脚本,其中包含来自 google:
的全局站点标签
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-4XXXXX5-2">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-4XXXXX5-2');
</script>
然后他们建议在闪亮的应用程序 header 中调用此 "google-analytics.js" 脚本文件,如下所示:
#ui.r
library(shiny)
shinyUI(fluidPage(
tags$head(includeScript("google-analytics.js")),
includeCSS("cerulean.css"),
titlePanel("Sunlight in the US"),
但是因为我使用的是闪亮的仪表板,所以我的闪亮布局有所不同...
#ui.r
library(shiny)
library(shinydashboard)
dashboardPage(
dashboardHeader(title = "Single Cell Database"),
dashboardSidebar(
sidebarMenu(
menuItem("P15 Clustering", tabName = "P15_Cluster", icon = icon("th")),
menuItem("P15 Violin Plots", tabName = "P15_Violin", icon = icon("th"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "P15_Cluster",
我似乎无法弄清楚在哪里放置...
tags$head(includeScript("google-analytics.js")),
...采用闪亮的仪表板格式。此外,由于 google 的代码格式不再与示例匹配,我对脚本函数的新格式没有信心。
任何有关在闪亮的仪表板 header 中调用 "google-analytics.js" 脚本的位置或有关如何格式化 "google-analytics.js" 文件中的代码的任何帮助或建议,我们将不胜感激!
我和你有同样的问题。我可以解决问题,并且按照 https://shiny.rstudio.com/articles/usage-metrics.html
中的教程进行操作后它就可以正常工作
第一步:您可以在google-analytics.js文件中使用以下代码:
(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',
'https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-4XXXXX5-2', 'auto');
ga('send', 'pageview');
$(document).on('change', 'select', function(e) {
ga('send', 'event', 'widget', 'select data', $(e.currentTarget).val());
});
$(document).on('click', 'button', function() {
ga('send', 'event', 'button', 'plot data');
});
第二个,你可以在"dashboardBody"中调用文件"google-analytics.js"。例如下面的语法:
dashboardBody(
tags$head(includeScript("google-analytics.js")),
tabItems(
tabItem(tabName = "P15_Cluster",
我有一个整理得很好的 R shiny (shinydashboard) 应用程序,它 运行 在服务器上。我希望能够跟踪它的使用情况,并且知道 google 分析是一个很好的解决方案。但是我 运行 遇到了设置问题。
我已尝试按照此处描述的说明进行操作 https://shiny.rstudio.com/articles/google-analytics.html
他们建议创建一个 google-analytics.js 脚本,其中包含来自 google:
的全局站点标签<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-4XXXXX5-2">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-4XXXXX5-2');
</script>
然后他们建议在闪亮的应用程序 header 中调用此 "google-analytics.js" 脚本文件,如下所示:
#ui.r
library(shiny)
shinyUI(fluidPage(
tags$head(includeScript("google-analytics.js")),
includeCSS("cerulean.css"),
titlePanel("Sunlight in the US"),
但是因为我使用的是闪亮的仪表板,所以我的闪亮布局有所不同...
#ui.r
library(shiny)
library(shinydashboard)
dashboardPage(
dashboardHeader(title = "Single Cell Database"),
dashboardSidebar(
sidebarMenu(
menuItem("P15 Clustering", tabName = "P15_Cluster", icon = icon("th")),
menuItem("P15 Violin Plots", tabName = "P15_Violin", icon = icon("th"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "P15_Cluster",
我似乎无法弄清楚在哪里放置...
tags$head(includeScript("google-analytics.js")),
...采用闪亮的仪表板格式。此外,由于 google 的代码格式不再与示例匹配,我对脚本函数的新格式没有信心。
任何有关在闪亮的仪表板 header 中调用 "google-analytics.js" 脚本的位置或有关如何格式化 "google-analytics.js" 文件中的代码的任何帮助或建议,我们将不胜感激!
我和你有同样的问题。我可以解决问题,并且按照 https://shiny.rstudio.com/articles/usage-metrics.html
中的教程进行操作后它就可以正常工作第一步:您可以在google-analytics.js文件中使用以下代码:
(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',
'https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-4XXXXX5-2', 'auto');
ga('send', 'pageview');
$(document).on('change', 'select', function(e) {
ga('send', 'event', 'widget', 'select data', $(e.currentTarget).val());
});
$(document).on('click', 'button', function() {
ga('send', 'event', 'button', 'plot data');
});
第二个,你可以在"dashboardBody"中调用文件"google-analytics.js"。例如下面的语法:
dashboardBody(
tags$head(includeScript("google-analytics.js")),
tabItems(
tabItem(tabName = "P15_Cluster",