ember-plausible
is an easy way to integrate and interact with Plausible analytics in your Ember applications.
- Ember.js v4.12 or above
- Ember CLI v4.12 or above
- Node.js v18 or above
- ember-auto-import v2
ember install ember-plausible
ember-plausible
provides a thin wrapper around the plausible-tracker npm package. It doesn't use the standalone Plausible script tag that is traditionally used when integrating Plausible. The tracker code will be part of the app bundle which has the benefit that ad-blockers can't block it (but they might still block the API calls to the server).
The easiest way to get started is to inject the service in your application route, and call the enable
method with your config.
// app/routes/application.js
// .. imports
export default class ApplicationRoute extends Route {
@service plausible;
beforeModel() {
this.plausible.enable({
domain: 'your-domain.be'
// other, optional options
});
}
}
Plausible supports sending custom events if you want to track things other than pageviews. To do this with ember-plausible
you can use the trackEvent
method of the PlausibleService.
// app/components/signup.js
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class SignupComponent extends Component {
@service plausible;
@action
signup(event) {
event.preventDefault();
// Store the form data
this.plausible.trackEvent('Signup');
}
}
If we have multiple signup components in our app and we want to track which one is the most effective, we could provide extra data when sending the custom event.
- this.plausible.trackEvent('Signup');
+ this.plausible.trackEvent('Signup', { name: this.args.name });
Plausible will then show the exact amount of signup events for each unique form.
Plausible makes it very easy to track outbound link clicks. To enable this functionality you need to set the enableAutoOutboundTracking
option to true
.
Alternatively you can call the enableAutoOutboundTracking
method on the Plausible service if Plausible was already enabled without the option being set to true
.
Once enabled, all external links in the app will send an event to your Plausible instance which can be viewed in the Plausible dashboard by following step 2 of the official outbound link tracking guide.
There is an open bug report which might affect your application. Be sure to double check that it doesn't affect you before enabling this functionality on production environments.
Since ember-plausible
doesn't use a separate tracking script, blocking that script with an ad-blocker isn't an option. Plausible does provide an alternative option which also works with this addon. You will have to reload the page after setting the localStorage value if Plausible was already enabled.
ember-plausible
uses the plausible-tracker package and exposes it as an easy-to-use service.
Enable Plausible.
The options object to initialize Plausible with.
If you want the same experience as the standalone Plausible script you only need to configure your domain name. Pageviews will automatically be tracked by default.
For more advanced use cases you can use the following options:
Name | Description | Type | Default value | Required |
---|---|---|---|---|
domain | The domain(s) you want to link to the events | string or an array of string s* |
- | Yes |
apiHost | The URL of the Plausible instance | string |
https://plausible.io |
No |
trackLocalhost | if true , apps running on localhost will send events |
boolean |
false |
No |
hashMode | if true , pageviews events will be sent when the URL hash changes. Enable this if you use the hash Location' option in Ember |
boolean |
false |
No |
enableAutoPageviewTracking | if true , all page changes will send an event |
boolean |
true |
No |
enableAutoOutboundTracking | if true , all clicks to external websites will send an event |
boolean |
false |
No |
* linking events to multiple domains isn't supported yet by the latest stable release of Plausible analytics in case you host your own instance. Only enable this if you are using https://plausible.io
as your API host or if you verified that your self-hosted version supports this feature.
Send a Pageview event (for the current page) to the API. This is useful if you want complete control over when pageview events are sent to the server.
eventData (optional): object
Extra event data you want to send
The properties you want to bind to the event
A Promise
which resolves when the pageview event is successfully sent.
Send a custom event to the API.
The name of the custom event. This is the value that you need to use when setting up custom goals in the Plausible dashboard.
The properties you want to bind to the event
eventData (optional): object
Extra event data you want to send
A Promise
which resolves when the custom event is successfully sent.
Enable the functionality that automatically sends pageview events to the API. This is only needed if you explicitly disable this functionality through the configuration options.
Disable the functionality that automatically sends pageview events to the API.
Enable the functionality that automatically sends outbound click events to the API.
Disable the functionality that automatically sends outbound click events to the API.
returns true
if the Plausible service was enabled by either the configuration option or calling enable
directly.
returns true
if Plausible is automatically tracking page changes.
returns true
if Plausible is automatically tracking outbound link clicks.
See the Contributing guide for details.
This project is licensed under the MIT License.