在R Flexdashboard中添加谷歌分析脚本。

问题描述 投票:0回答:1

我不知道如何在没有shiny的情况下使用flexdashboard添加谷歌分析。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-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
1个回答
0
投票

我使用的是flexdashboard,我包含了一个包含谷歌分析代码的HTML头。它是在这里描述的 如何在RMarkdown生成的GitHub页面中加入Google Analytics?

所以有了这个,应该就可以了

---
title: "test"
author: "test"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    vertical_layout: fill
    includes:
       in_header: GA_Script.html
---
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.