You simply require the GA JavaScript to trigger, if you are in RMarkdown you can paste the JS straight into the document
e.g.:
---
title: "Untitled"
author: "Mark Edmondson"
date: "11/11/2017"
output: html_document
---
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXX-2');
</script>
## 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 <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedd