Plausible
Set up Plausible for privacy-focused analytics.
The plugin uses the Plausible Events API to send events server-side. Plausible is privacy-focused, cookie-free, and GDPR-compliant by default.
Setup
Register your domain
Create a site in your Plausible dashboard. The domain you register (e.g., example.com) is used to identify your site in event payloads.
Add environment variable
PLAUSIBLE_DOMAIN="example.com"Start tracking
import { Analytics } from '@robojs/analytics'
Analytics.event('command_used', {
data: { command: 'ping' }
}) import { Analytics } from '@robojs/analytics'
Analytics.event('command_used', {
data: { command: 'ping' }
})How it works
Each call to Analytics.event() or Analytics.view() sends a POST request to the Plausible Events API:
https://plausible.io/api/eventEvent mapping
The plugin maps EventOptions fields to the Plausible payload:
| EventOptions field | Plausible field | Notes |
|---|---|---|
data | props | Must be an object with 30 or fewer fields |
domain | domain | Overrides the configured domain per-event |
url | url | Defaults to https://{domain}/ |
Fields like sessionId, userId, revenue, action, actionType, label, and type are not used by the Plausible engine directly. Include them in data if you want them as custom properties.
Page views
Analytics.view() sends a pageview event. The page name is converted to a URL-safe slug and appended to the domain:
Analytics.view('Settings Page')
// URL becomes: https://example.com/settings-pageAnalytics.view('Settings Page')
// URL becomes: https://example.com/settings-pageThe slugification normalizes diacritics, removes special characters, and converts spaces to hyphens.
Custom properties
Pass custom properties through the data field:
Analytics.event('feature_used', {
data: {
feature: 'leaderboard',
guild_size: 'large',
user_role: 'admin'
}
})Analytics.event('feature_used', {
data: {
feature: 'leaderboard',
guild_size: 'large',
user_role: 'admin'
}
})Plausible enforces a maximum of 30 custom properties per event. If data has more than 30 fields, the plugin throws an error. Keep your property count under this limit.
Domain override
Override the configured domain for a specific event:
Analytics.event('cross_site_action', {
domain: 'other-site.com',
data: { source: 'discord-bot' }
})Analytics.event('cross_site_action', {
domain: 'other-site.com',
data: { source: 'discord-bot' }
})URL override
Override the auto-generated URL:
Analytics.view('Custom Page', {
url: 'https://example.com/custom/path'
})Analytics.view('Custom Page', {
url: 'https://example.com/custom/path'
})Request headers
The plugin sends hardcoded headers with each request:
| Header | Value |
|---|---|
Content-Type | application/json |
X-Forwarded-For | 127.0.0.1 |
User-Agent | Hardcoded browser user agent string |
These headers are required by the Plausible API. The X-Forwarded-For and User-Agent values are static since server-side events don't have a real browser context.
Programmatic configuration
Instead of environment variables, pass the domain directly to the constructor:
import { PlausibleAnalytics } from '@robojs/analytics'
export default {
engine: new PlausibleAnalytics('example.com')
}import { PlausibleAnalytics } from '@robojs/analytics'
export default {
engine: new PlausibleAnalytics('example.com')
}Constructor options take priority over the PLAUSIBLE_DOMAIN environment variable.
Error handling
The Plausible engine handles errors as follows:
- Missing event name: Logs an error and returns early. No exception thrown.
- Data exceeds 30 fields: Throws an
Error. This propagates to the caller. - API errors: Caught internally and logged as a warning.
- Missing domain: No explicit validation. Results in malformed URLs.
Troubleshooting
Events not appearing in Plausible dashboard
- Verify the domain in your
.envmatches exactly what you registered in Plausible. - Domain mismatches cause events to be silently ignored by the Plausible API.
Error about exceeding 30 fields
- Reduce the number of properties in your
dataobject. Split large payloads across multiple events if needed.
