Website Traffic Metrics with Plausible Analytics

Use Plausible Analytics as an alternative to Google Analytics

Plausible Analytics
plausible
quarto
hugo
website traffic metrics
Google Analytics
Author
Affiliations

Layal Christine Lettry

cynkra GmbH

University of Fribourg, Dept. of Informatics, ASAM Group

Published

November 2, 2023

How can you monitor your website statistics for your Hugo and Quarto websites?

Introduction

In this article, I will explain how to utilize Plausible Analytics with a Hugo website featuring the Hugo Apéro theme and with a Quarto website.

Motivation

When I wanted to install Google Analytics for my personal Hugo and Quarto websites to gather usage statistics, I came across this GitHub issue, which piqued my interest.

According to Seth Ariel Green, the author of the GitHub issue, using Google Analytics was discouraged, and an alternative tool was recommended to track website traffic, namely Plausible Analytics.

As a result, I sought information on how to install Plausible Analytics to begin measuring site traffic metrics for my personal website built with Hugo Apéro. Unfortunately, I couldn’t find a clear description of the installation process. This article aims to share my experience with you.

Why Choose Plausible Analytics Over Google Analytics?

Background

In 2022, some countries banned the use of Google Analytics, citing it as unlawful and in violation of the General Data Protection Regulation (GDPR). Countries such as France, Italy, Austria, and Denmark, among others, implemented these restrictions. Additional information is available on this webpage.

Advantages of Plausible Analytics

Three key advantages of using Plausible Analytics over Google Analytics are as follows1:

  1. Plausible Analytics is a lightweight and straightforward analytics tool that provides clear statistics on a single page. This contrasts with Google Analytics, which requires exploration and understanding of its various options and dashboards.

  2. The analytics script of Plausible Analytics is smaller and lighter than that of Google Analytics, resulting in no slowdown for your website.

  3. Plausible Analytics prioritizes visitor privacy and avoids the use of cookies.

For more reasons to choose Plausible Analytics, you can refer to its GitHub repository since it is open-source.

Integration of Plausible Analytics into your website

To start tracking your website stats with Plausible Analytics, follow these steps:

  1. Register your account.

  2. Add your website details.

If you have a Hugo Website with the Hugo Apéro Theme

  1. Add your JavaScript snippet to the <head> of your website. If your website is built with Hugo Apéro, follow these sub-steps:

    1. Create a new file in themes/hugo-apero/layouts/partials/head_custom.html, similar to what’s done in this commit).

    2. Insert { partial "head_custom.html" . } into themes/hugo-apero/layouts/partials/head.html, as shown in this line of code.

If you have a Quarto Website or Blog

  1. Add your JavaScript snippet to the <head> of your website. Follow these sub-steps:

    1. Create a new html file at the root of your quarto project which you will call “plausible.html”, similar to what’s done in the plausible file of this blog.

    2. Insert the following code into your _quarto.yml file.

format:
  html:
    include-after-body: plausible.html

Start tracking your website stats

  1. Push your modifications and deploy your website.

  2. Verify that the script is installed on your website by inspecting the page source and searching for the string “data-domain.”

  3. If everything went as planned, you will receive an email beginning with “Congrats! The Plausible script has been installed correctly on your website.”

Congratulations, you’ve done it!

Analyze Your Data with the R Package plausibler

With the R package plausibler, you can query and summarize your website traffic metrics directly from your R console. To get started, generate an API key, which you can easily obtain. Access your settings page by clicking on the three vertical dots next to your username at the top right of the Plausible Analytics page. In the “API Keys” section, generate and copy an API key into the plausibler::pa_set() function, as explained in the README file of the GitHub repository plausibler.

Then, follow the instructions in the README to access all your website statistics directly within your R session.

Acknowledgements

Many thanks to

Footnotes

  1. My reference.↩︎

Citation

BibTeX citation:
@online{lettry2023,
  author = {Lettry, Layal Christine},
  title = {Website {Traffic} {Metrics} with {Plausible} {Analytics}},
  date = {2023-11-02},
  url = {https://rdiscovery.netlify.app/posts/2023-11-02_plausible/},
  langid = {en}
}
For attribution, please cite this work as:
Lettry, Layal Christine. 2023. “Website Traffic Metrics with Plausible Analytics.” November 2, 2023. https://rdiscovery.netlify.app/posts/2023-11-02_plausible/.