【发布时间】:2020-08-22 20:49:43
【问题描述】:
我不知道如何使用没有闪亮的 flexdashboard 添加 Google Analytics。谷歌分析方面很好,因为我在不同的 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-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>
【问题讨论】:
标签: r shiny google-analytics knitr flexdashboard