I couldn't figure out how to add Google Analytics using flexdashboard without shiny. Google analytics side is fine because I manually tried it on different html pages (not generated by R side) and there is no issue. Once I knit the below code, there is no issue or warning. However, the source code of the generated html page from R side is also not include anything related with google-analytics side (such as searching id does not find anything). I have also upload the page to the server in order to see whether analytics side might show something or not. Of course, it does show nothing. So, what is the proper way of inserting google-analytics side into flexdashboard panel without shiny app as in the below code?
Minimal code (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 (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>
I'm using flexdashboard, and I included a header with an HTML that contains the google analytics code. It is described here How to include Google Analytics in an RMarkdown generated GitHub Page?
So with this it should work
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
includes:
in_header: GA_Script.html
---