How to connect bookdown with google analytics
- Create Google Analytics account
- Choose “Analytics Accounts”
- Create “Properties & Apps”
- In “Data Streams”, “Add stream” with your website URL
- Under “Tagging Instructions”, click on gtag.js. You should see something like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DMNX2X65HQ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
where you see GA_MEASUREMENT_ID
, you will your own number.
- Create a
.html
file and paste the code script and save it in your bookdown folder. Name itgoogle_analytics.html
- Go to
_output.yml
, change it to
bookdown::gitbook:
includes:
in_header: [google_analytics.html]
css: style.css
- Upload your bookdown
- Go to Google Analytics your Google Analytics account. And voila.