Google Analytics in Interactive Rmarkdown documents



Hi. Could I have some tips about how must I use Google Analytics scripts inside an interactive Rmarkdown document? I success using it in a Shiny application. But it does not work if I use it in a similar way in an interactive Rmarkdown documents. Perhaps I must be carefull about where to put the includeScript() function calling???
Thanks in advance


You simply require the GA JavaScript to trigger, if you are in RMarkdown you can paste the JS straight into the document


title: "Untitled"
author: "Mark Edmondson"
date: "11/11/2017"
output: html_document
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXX-2');

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedd


I must get the script inside the head tag. Will I get this in such a simple way? I will try at once. once!!!Thanks


Ok. Not necessary your reply to my second question, I tried you solution and it works perfect. Thanks!!!