Skip to content

feat: Add Umami analytics and view count to article details #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tsanie
Copy link

@tsanie tsanie commented Feb 28, 2025

This PR introduces umami analytics for articles and displays a pageview tag after the reading time, as shown below:
image

Users can enable it by putting these parameters in a configuration file such as hugo.yaml:

params:
  analytics:
    umami:
      enabled: true
      host: https://u.example.com # your umami service URL
      siteId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
      token: # not required, you can use the cloudflare worker proxy, see https://blahba.com/en/p/using-umami-with-cloudflare-worker/
      startAt: # Date constructor parameters, such as `1735689600000` or `2025-01-01`

You can get a token via POST /api/auth/login with data { "username": "<your user>", "password": "<password>" }.

If you are worried about leaking the token, you can wrap it with a Cloudflare Worker, see this article: https://blahba.com/en/p/using-umami-with-cloudflare-worker/

- Added conditional rendering for view count in article details based on `Site.Params.Analytics`.
- Updated Umami analytics script to use structured parameters and fixed script inclusion.
- Included Umami analytics script in the head section.
@tsanie tsanie changed the title **feat:** Add Umami analytics and view count to article details feat: Add Umami analytics and view count to article details Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant