Installation Guide for Quarto Adsense Extension

Installation

To seamlessly integrate the adsense extension into your Quarto project, follow these straightforward steps:

  1. Open Your Terminal: Open your terminal or command prompt.

  2. Execute the Installation Command: Run the following command to automatically download and install the extension:

    quarto add coatless-quarto/adsense

    This command installs the adsense extension in the _extensions subdirectory of your Quarto project. If you’re utilizing version control, make sure to include this directory in your repository.

Google Adsense Setup: Adding 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 your Google Publisher ID:

  1. Create ads.txt File: In the root of your project, create a new file named ads.txt.

  2. 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.

  3. 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.

  4. **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.

Usage

You can configure the adsense extension in either of the following ways:

  1. Global Configuration Using a Configuration File: Set up the extension globally by incorporating the relevant configuration in either the _quarto.yml or _metadata.yml file. This ensures consistent usage across all documents in your project.

  2. Document-specific Configuration in YAML Header: Customize the extension settings for individual documents by adding configuration details to the YAML header of the respective Quarto document. This approach allows for fine-tuned control on a per-document basis.

Select the configuration method that best suits your project’s needs to learn more!