Tracks all outbound link clicks automatically
Call this if you don't want to manually manage these links.
It works using a MutationObserver to automagically detect link nodes throughout your application and bind click
events to them.
Optionally takes the same parameters as MutationObserver.observe
.
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible()
// This tracks all the existing and future outbound links on your page.
enableAutoOutboundTracking()
The returned value is a callback that removes the added event listeners and disconnects the observer
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible()
const cleanup = enableAutoOutboundTracking()
// Remove event listeners and disconnect the observer
cleanup()
Tracks the current page and all further pages automatically.
Call this if you don't want to manually manage pageview tracking.
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible()
// This tracks the current page view and all future ones as well
enableAutoPageviews()
The returned value is a callback that removes the added event listeners and restores history.pushState
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible()
const cleanup = enableAutoPageviews()
// Remove event listeners and restore `history.pushState`
cleanup()
Callback called when the event is successfully sent.
Properties to be bound to the event.
Data passed to Plausible as events.
The current device's width.
Defaults to window.innerWidth
The referrer to bind the event to.
Defaults to document.referrer
The URL to bind the event to.
Defaults to location.href
.
Options used when initializing the tracker.
The API host where the events will be sent.
Defaults to 'https://plausible.io'
The domain to bind the event to.
Defaults to location.hostname
If true, pageviews will be tracked when the URL hash changes. Enable this if you are using a frontend that uses hash-based routing.
Set to true if you want events to be tracked when running the site locally.
Options used when tracking Plausible events.
Tracks a custom event.
Use it to track your defined goals by providing the goal's name as eventName
.
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible()
// Tracks the 'signup' goal
trackEvent('signup')
// Tracks the 'Download' goal passing a 'method' property.
trackEvent('Download', { props: { method: 'HTTP' } })
Manually tracks a page view.
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible()
// Track a page view
trackPageview()
Initializes the tracker with your default values.
import Plausible from 'plausible-tracker'
const { enableAutoPageviews, trackEvent } = Plausible({
domain: 'my-app-domain.com',
hashMode: true
})
enableAutoPageviews()
function onUserRegister() {
trackEvent('register')
}
var Plausible = require('plausible-tracker');
var { enableAutoPageviews, trackEvent } = Plausible({
domain: 'my-app-domain.com',
hashMode: true
})
enableAutoPageviews()
function onUserRegister() {
trackEvent('register')
}
Default event parameters that will be applied to all requests.
Generated using TypeDoc
Cleans up all event listeners attached.