A simple Hexo plugin to inject Plausible Analytics script in your pages.
Compatibility: Hexo 3 and above
- Extremely simple configuration
- Supports custom domain
- Supports exclude directive
- Supports self-hosting
- Inject the script only on specific page types (page, post, draft, archive, ...)
In the root directory of your project run:
$ npm install hexo-plausible-analytics
To enable the plugin add this to your config.yml
:
plausible:
enable: true
domain: YOUR_DOMAIN
domain
is the domain name of your site and is the only required property. Be sure to remove https
and www
from the URL. If your site is https://www.yourdomain.com
then your configuration should look like this:
plausible:
enable: true
domain: yourdomain.com
Will result in:
<script async defer data-domain="yourdomain.com" src="https://plausible.io/js/plausible.js"></script>
The pages
property is an array that allows you to specify on which page types to inject the script. Valid values are:
default
: Inject to every page. This is the default configuration.home
: Only inject to home page (which hasis_home()
helper beingtrue
)post
: Only inject to post pages (which hasis_post()
helper beingtrue
)page
: Only inject to pages (which hasis_page()
helper beingtrue
)archive
: Only inject to archive pages (which hasis_archive()
helper beingtrue
)category
: Only inject to category pages (which hasis_category()
helper beingtrue
)tag
: Only inject to tag pages (which hasis_tag()
helper beingtrue
)
The following configuration will inject the scripts only on the home page and all posts:
plausible:
enable: true
domain: yourdomain.com
pages:
- home
- post
Add the subdomain
property and specify your subdomain if you want to serve the Plausible script as a first-party connection.
plausible:
enable: true
domain: yourdomain.com
subdomain: stats
Will result in:
<script async defer data-domain="yourdomain.com" src="https://stats.yourdomain.com/js/index.js"></script>
Specify in the exclude
property the pages that you don't want to be tracked. You can enter them as a comma-separated string or as an array. Check the official guide on how to format them.
plausible:
enable: true
domain: yourdomain.com
exclude: '/blog4, /rule/*, /how-to-*, /*/admin'
Or as an array:
plausible:
enable: true
domain: yourdomain.com
exclude:
- /blog4
- /rule/*
- /how-to-*
- /*/admin'
Both these configurations will result in:
<script async defer data-domain="yourdomain.com" src="https://plausible.io/js/plausible.exclusions.js" data-exclude="/blog4, /rule/*, /how-to-*, /*/admin"></script>
The exclude
property also works if you configured a subdomain
:
plausible:
enable: true
domain: yourdomain.com
subdomain: stats
exclude: '/blog4, /rule/*, /how-to-*, /*/admin'
Will result in:
<script async defer data-domain="yourdomain.com" src="https://stats.yourdomain.com/js/index.exclusions.js" data-exclude="/blog4, /rule/*, /how-to-*, /*/admin"></script>
In case you are self hosting you can specify the src
property:
plausible:
enable: true
domain: yourdomain.com
src: https://yourdomain.com/plausible.js
Will result in:
<script async defer data-domain="yourdomain.com" src="https://yourdomain.com/plausible.js"></script>
In case set the exclude
property:
plausible:
enable: true
domain: yourdomain.com
src: https://yourdomain.com/plausible.js
exclude: '/blog4, /rule/*, /how-to-*, /*/admin'
Will result in:
<script async defer data-domain="yourdomain.com" src="https://yourdomain.com/plausible.js" data-exclude="/blog4, /rule/*, /how-to-*, /*/admin"></script>
I work on the develop
branch and release from the main
. If you want to contribute fork this repository and create a new branch from develop
. Once you are done open a Pull Request to develop
.