【问题标题】:Adding Google Analytics script into R flexdashboard将 Google Analytics 脚本添加到 R flexdashboard
【发布时间】: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


    【解决方案1】:

    我正在使用 flexdashboard,并包含一个带有 HTML 的标题,其中包含 google 分析代码。这里有描述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
    ---
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2021-04-17
      • 2012-10-20
      相关资源
      最近更新 更多