The adsense
extension allows you to incorporate Google Adsense (GADS) ad's on various Quarto formats, including HTML, Websites, and Books.
This extension is required as Quarto does not natively support Google Adsense, but does have support for Google Analytics.
To install the adsense
extension, follow these steps:
Open your terminal.
Execute the following command:
quarto add coatless-quarto/adsense
This command will download and install the extension under the _extensions
subdirectory of your Quarto project. If you are using version control, ensure that you include this directory in your repository.
There are two modes available for the extension:
Note: Ads may take up to an hour to appear on the page/project.
If you have a website or book, you can use either the _quarto.yml
or _metadata.yml
files to avoid needing to consistently set the value. Add into the configuration file:
adsense:
publisher-id: ca-pub-XXXXXXXXXXXXXXXX
filters:
- adsense
where XXXXXXXXXXXXXXXX
in publisher-id
is your Google Adsense Publisher ID.
If you wish to disable ads on a specific page, then add to the Quarto document's YAML header area:
adsense:
enable-ads: false
For more information, please see Quarto's documentation on Shared Metadata.
If you only have one HTML document, we recommend setting up the extension by placing the required fields into the document's header section, e.g.
---
title: "Demo Setup"
author: "FirstName LastName"
adsense:
publisher-id: ca-pub-XXXXXXXXXXXXXXXX
filters:
- adsense
---
ads.txt
To ensure smooth integration with Google Adsense, it's essential to create a standalone file named ads.txt
within your project directory that identifies the domain as being authorized to serve ads. Follow these steps to include the ads.txt
file:
Create ads.txt
File:
In the root of your project, create a new file named ads.txt
.
Add Google Publisher ID:
Open ads.txt
and insert the following line, replacing XXXXXXXXXXXXXXXX
with your actual Google Publisher ID:
google.com, pub-XXXXXXXXXXXXXXXX, DIRECT, f08c47fec0942fa0
This line informs Google's web crawler about your association with the provided Publisher ID. For an example, please see the docs/ads.txt
.
Save and Include in Version Control:
Save the changes to ads.txt
and ensure that the file is included in your version control system if you're using one.
Register ads.txt
in _quarto.yml:
Open the _quarto.yml
configuration and add the resources
line under the project key.
project:
type: website # default, book, revealjs
resources:
- ads.txt
This ensures the additional file resources are copied to the output directory.
This step is crucial for validating your ownership of the website and enabling a smooth interaction between your Quarto-generated content and Google Adsense. Remember to replace XXXXXXXXXXXXXXXX
with your specific Google Publisher ID.
This Quarto extension is open source software and is not affiliated with Google. The extension is at best a community effort to simplify the integration of Google's Adsense product inside of Quarto websites.