distill icon indicating copy to clipboard operation
distill copied to clipboard

Google analytics on a single distill page?

Open ColinConwell opened this issue 3 years ago • 1 comments

Question: is it possible to include the google_analytics: 'tracking_id' on a single static distill article? (Generated with rmarkdown::render('name_of_page.Rmd')?

Or is some sort of site rendering necessary?

Ideally, I'd like to be able to add analytics (without manually editing the .html file) without creating an entire site.

ColinConwell avatar Dec 08 '21 19:12 ColinConwell

This can be done by using includes: (see https://github.com/rstudio/distill/issues/378)

Create an HTML file with the analytics scripts. I was able to find mine by inspecting an existing page and finding the

  1. googletagmanager script
  2. google-site-verification meta line

Pasting that into the filename.html file and then pointing to it in the YAML did the trick.

Add to YAML:

includes:
   in_header: filename.html

Knit file individually.

edornshuld avatar Feb 15 '22 21:02 edornshuld