将 Google 分析脚本添加到 R flexdashboard
Adding Google Analytics script into R flexdashboard
我无法弄清楚如何在没有闪亮的情况下使用 flexdashboard 添加 Google 分析。 Google 分析端很好,因为我在不同的 html 页面(不是由 R 端生成)上手动尝试过,没有问题。一旦我编写了以下代码,就没有问题或警告。但是,R 端生成的 html 页面的源代码也不包含任何与 google-analytics 端相关的内容(例如搜索 id 没有找到任何内容)。我还将页面上传到服务器,以查看分析方面是否会显示某些内容。当然,它确实没有显示任何内容。那么,将 google-analytics 端插入 flexdashboard 面板的正确方法是什么,如下面的代码所示,没有闪亮的应用程序?
最小代码(main.Rmd)
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(htmltools)
htmltools::includeHTML("google-analytics.html")
```
test1
=======================================================================
**testttt**
testttt
**testttt2**
testttt
Google 分析(google-analytics.html)
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
</script>
我正在使用 flexdashboard,我包含了一个 header 和一个包含 google 分析代码的 HTML。在这里描述 How to include Google Analytics in an RMarkdown generated GitHub Page?
所以它应该可以工作
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
includes:
in_header: GA_Script.html
---
我无法弄清楚如何在没有闪亮的情况下使用 flexdashboard 添加 Google 分析。 Google 分析端很好,因为我在不同的 html 页面(不是由 R 端生成)上手动尝试过,没有问题。一旦我编写了以下代码,就没有问题或警告。但是,R 端生成的 html 页面的源代码也不包含任何与 google-analytics 端相关的内容(例如搜索 id 没有找到任何内容)。我还将页面上传到服务器,以查看分析方面是否会显示某些内容。当然,它确实没有显示任何内容。那么,将 google-analytics 端插入 flexdashboard 面板的正确方法是什么,如下面的代码所示,没有闪亮的应用程序?
最小代码(main.Rmd)
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(htmltools)
htmltools::includeHTML("google-analytics.html")
```
test1
=======================================================================
**testttt**
testttt
**testttt2**
testttt
Google 分析(google-analytics.html)
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
</script>
我正在使用 flexdashboard,我包含了一个 header 和一个包含 google 分析代码的 HTML。在这里描述 How to include Google Analytics in an RMarkdown generated GitHub Page?
所以它应该可以工作
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
includes:
in_header: GA_Script.html
---