How to connect bookdown with google analytics

  1. Create Google Analytics account
  2. Choose “Analytics Accounts”
  3. Create “Properties & Apps”
  4. In “Data Streams”, “Add stream” with your website URL
  5. Under “Tagging Instructions”, click on gtag.js. You should see something like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'GA_MEASUREMENT_ID');

where you see GA_MEASUREMENT_ID, you will your own number.

  1. Create a .html file and paste the code script and save it in your bookdown folder. Name it google_analytics.html
  2. Go to _output.yml, change it to
    in_header: [google_analytics.html]
  css: style.css
  1. Upload your bookdown
  2. Go to Google Analytics your Google Analytics account. And voila.
Mike Nguyen, PhD
Mike Nguyen, PhD
Visitng Scholar

My research interests include marketing, and social science.