Quarto: Adding `include-in-header` for _quarto.yml to Populate Script on All Website Pages

Hello Rstud..., er, Posit Community,

First, thanks to everyone who works on Quarto for creating and maintaining such a great publishing system.

I understand JavaScript snippets can be included in the header of individual HTML files generated by Quarto as described in the Quarto documentation. However, is there a way to do that site-wide? Perhaps via the _quarto.yml file, similar to how Quarto nicely populates Google Analytics' gtag.js just by providing the GA4 tag in the yaml option?

Motivation, our org adopted Fullstory and I need to include the JS tag similar to <script type="text/javascript" src="//URL_TK.js"></script>so that it populates on each page. I've gitstalked the Quarto gallery websites and some others to see if any incorporate similar functionality, but wasn't able to find anything similar.

Apologies if I've missed this in the docs. Any recommendations anyone here has would be greatly appreciated.

Thanks very much,

Kurtis

You could define format metadata as shared metadata inside _quarto.yml or even at folder level

So you could add include-in-header at this level and it should be merged correctly with any other document level meta Quarto - Project Basics

2 Likes

Merci bien, @cderv .

This worked perfectly. FWIW, including the YAML placement (under format: html: section) below in case anyone else finds this and has questions...including my future self.

Thanks again.

Kurtis

format:
  html:
    theme: litera
    css: styles.css
    include-in-header:
      - text: |
          <script type="text/javascript" src="URL_TK.js"></script>
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.