carbon/plausible
composer require carbon/plausible
Track visits of your Neos site with plausible.io
1.9.3
- Requires
- neos/neos: ^5.3 || ^7.0 || ^8.0
- neos/cache: ^6.3 || ^7.0 || ^8.0
- neos/fusion-afx: *
- carbon/eel: ^1.12.0 || ^2.0
- tedivm/jshrink: ^1.4
- Suggest
- neos/seo: SEO configuration and tools for Neos.
Carbon.Plausible Package for Neos CMS
Easily integrate Plausible Analytics into your Neos site.
Introduction
Plausible is a lightweight and open-source website analytics tool. It doesn't use cookies and is fully compliant with GDPR, CCPA, and PECR. This plugin is meant to remove all friction from adding the Plausible Analytics tracking script code to your Neos site. All you need to do is define your Plausible domain in your Neos Settings.yaml
file.
Features
- Multi-site compatibility
- Backend module
- Check if the requested domain matches the defined domain to track
- Enabled per default only on
Production
environment - Embed stats directly into the Neos Backend
Multi-site compatibility
If you run a multi-site setup, we got you covered! You can set different trackings for the sites based on the root node name.
Backend module
This package adds a backend module to your Neos instance, which helps check your configuration and opt-out your browser for tracking.
If a backend user is not an administrator, he'll get a different view:
It also checks if the resulting javascript path doesn't return a 404 error:
NodeType mixins for disable tracking on a document or set custom events
This package contains two mixins:
- Carbon.Plausible:Mixin.CustomEvent: This allows you to set custom events to a document via the inspector. Of course, you can do this also directly in your JavaScript or Fusion
- Carbon.Plausible:Mixin.DoNotTrack: This allows you to disable the tracking for a specific document
Opt out and exclude your visits from the analytics
By default, Plausible Analytics tracks every visitor to your website. When you're working on your site, you might not want to record your own visits and page views. To prevent counting your visits, you can set a special localStorage flag in the browser. Here's how.
- Go to
your-domain.tld/~/disable-tracking
. This sets the flag and redirects the visitor to the homepage. Great for people without access to the Neos Backend. - As an Editor, you can enable/disable the flag also in the Plausible management module:
your-domain.tld/neos/management/plausible
- You can do this also by yourself by following the excluding guide on plausible.io
Installation
Run the following command in your site package
composer require --no-update carbon/plausible
Then run composer update
in your project root.
Configuration
Single-site setup
If you have a single site setup, you can adjust the configuration under the key Carbon.Plausible.default
in your Settings.yaml
:
Key | Default | Description |
---|---|---|
domain |
null |
Set here the plausible domain. This setting is required |
host |
null |
If you have set a custom domain, you can set it here. Example: stats.jonnitto.ch |
hashBasedRouting |
false |
If you want the enable Hash-based routing, set this to true |
exclusions |
false |
If you want to exclude specific pages from the analytics, you can set an array with strings or a string. If you want to load just the exclusion variant, set this to true |
outboundLinks |
false |
If you want the enable outbound link click tracking, set this to true |
customEvents |
false |
If you want to set custom events in your javascript, set this to true or a string. If set to a string, this whole string gets included on every document. If you set custom events via Fusion or the Carbon.Plausible:Mixin.CustomEvent mixin, you don't have to set it to true . The snippet gets activated automatically if needed. The inline javascript get's minified with JShrink |
sharedLink |
null |
If you have opened up your [website stats to the public] or created a [private and secure link], enter it to enable the embedded view of the stats in the backend. |
Multi-site setup
If you run multiple sites on one Neos installation, you can set this under the key Carbon.Plausible.sites
in your Settings.yaml
. Be aware that if you set one value in Carbon.Plausible.default
, these are set as the new fallback value. For example, if you set Carbon.Plausible.default.outboundLinks
to true
, is outboundLinks
set to true
per default for all sites. Of course, you can disable this again if you set this to false
on your site setting.
Example:
Carbon:
Plausible:
sites:
myfirstsite:
host: stats.domain.com
domain: domain.com
outboundLinks: true
sharedLink: https://plausible.io/share/domain.com?auth=abcdefghijklmnopqrstu
mysecondsite:
domain: domain.org
hashBasedRouting: true
exclusions: "/blog4, /rule/*, /how-to-*, /*/admin"
sharedLink: https://plausible.io/domain.org
mythirdsite:
domain: domain.net
customEvent: "plausible('Download', {props: {method: 'HTTP'}})"
exclusions:
- /blog4
- /rule/*
- /how-to-*
- /*/admin
The key of the site (e.g. myfirstsite
) is the root node name found under Administration » Sites Management.
Fusion Component
The main Fusion component is Carbon.Plausible:Component.TrackingCode. This component gets included into Neos.Neos:Page under the path plausibleTrackingCode
. So if you want to add a custom event to a ceratin document, you can do it like this:
prototype(Vendor.Site:Document.NotFound) < prototype(Neos.Neos:Page) {
plausibleTrackingCode.customEvents = 'plausible("404",{ props: { path: document.location.pathname } });'
}