2017-10-04 1 views
2

서버에서 실행되는 R 반짝이 (shinydashboard) 앱을 잘 분류했습니다. 나는 그것의 사용법을 추적하고 google analytics가 이것을위한 좋은 해결책다는 것을 알 수 있고 싶다. 그러나 나는 그것을 설정하는 문제에 부딪쳤다.반짝이는 대시 보드 앱용 Google 웹 로그 분석

나는

https://shiny.rstudio.com/articles/google-analytics.html 그들은 구글의 글로벌 사이트 태그가 포함 된 구글 - analytics.js를 스크립트의 생성 제안 여기에 설명 된 지침에 따라 시도했다 : "그들은 다음이 제안

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

을 google-analytics.js "스크립트 파일은 다음과 같이 반짝이는 응용 프로그램 헤더에서 호출해야합니다.

#ui.r 
library(shiny) 
shinyUI(fluidPage(

    tags$head(includeScript("google-analytics.js")), 
    includeCSS("cerulean.css"), 

    titlePanel("Sunlight in the US"), 

그러나 나는 신을 사용하고 있기 때문에 내 반짝 레이아웃이 다른 Y 대시 보드 ... 내가 배치 할 곳 ...

tags$head(includeScript("google-analytics.js")), 

을 ... 반짝 대시 보드 형식으로 알아낼 수없는 것

#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", 

. 또한 Google 검색 코드 형식이 더 이상 예제와 일치하지 않기 때문에 새로운 스크립트 형식의 형식을 신뢰할 수 없습니다.

빛나는 대시 보드 헤더에서 'google-analytics.js'스크립트를 호출하는 위치 나 'google-analytics.js'파일에서 코드의 형식을 지정하는 방법에 대한 도움이나 조언을 보내 주시면 감사하겠습니다.

답변

1

나는 동일한 문제가 있습니다. 나는 문제를 해결할 수 있으며 https://shiny.rstudio.com/articles/usage-metrics.html

첫 번째 단계에서 튜토리얼을 수행 한 후에도 작동합니다 : 당신은 구글-에서 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'); 
}); 

두 번째, 당신이 호출 할 수를 "google-analytics.js"파일을 "dashboardBody"에 저장하십시오. 아래 구문과 같습니다 :

dashboardBody(
    tags$head(includeScript("google-analytics.js")), 
    tabItems(
     tabItem(tabName = "P15_Cluster",