### Install Plausible Tracker
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Install the Plausible Tracker library using npm or yarn.
```bash
npm install plausible-tracker
yarn add plausible-tracker
```
--------------------------------
### Plausible(defaults?)
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Initializes the Plausible tracker and returns all tracking functions. This should typically be called once at application startup.
```APIDOC
## Plausible(defaults?)
### Description
Creates and returns all tracking functions, binding the provided default options to every subsequent event call. Call this once, typically at app startup.
### Method
Initializer function
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```ts
import Plausible from 'plausible-tracker'
// Minimal initialization — domain defaults to location.hostname
const plausible = Plausible()
// Full initialization with all available options
const plausible = Plausible({
domain: 'my-app.com', // Your site's domain as registered in Plausible
apiHost: 'https://plausible.io', // Change if self-hosting, e.g. 'https://stats.example.com'
trackLocalhost: false, // Set true to send events from localhost (dev mode)
hashMode: false, // Set true for hash-based SPA routing (#/page)
})
const { trackEvent, trackPageview, enableAutoPageviews, enableAutoOutboundTracking } = plausible
```
### Response
#### Success Response (200)
Returns an object containing tracking functions: `trackEvent`, `trackPageview`, `enableAutoPageviews`, `enableAutoOutboundTracking`.
#### Response Example
```json
{
"trackEvent": "function",
"trackPageview": "function",
"enableAutoPageviews": "function",
"enableAutoOutboundTracking": "function"
}
```
```
--------------------------------
### Initialize Plausible Tracker
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Initialize the tracker once at app startup. Minimal initialization uses the current location.hostname as the domain. Full initialization allows specifying domain, API host, localhost tracking, and hash mode for SPAs.
```typescript
import Plausible from 'plausible-tracker'
// Minimal initialization — domain defaults to location.hostname
const plausible = Plausible()
// Full initialization with all available options
const plausible = Plausible({
domain: 'my-app.com', // Your site's domain as registered in Plausible
apiHost: 'https://plausible.io', // Change if self-hosting, e.g. 'https://stats.example.com'
trackLocalhost: false, // Set true to send events from localhost (dev mode)
hashMode: false, // Set true for hash-based SPA routing (#/page)
})
const { trackEvent, trackPageview, enableAutoPageviews, enableAutoOutboundTracking } = plausible
```
--------------------------------
### Initialize Plausible Tracker
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Initialize the Plausible tracker with your domain. This is required before tracking any events. The `domain` option is mandatory if not using the default `location.hostname`.
```typescript
import Plausible from 'plausible-tracker'
const plausible = Plausible({
domain: 'my-app.com'
})
```
--------------------------------
### Configure Self-hosted Plausible Instance
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Points the tracker to a self-hosted Plausible server by setting the `apiHost` option during initialization. Events are sent to the specified host's `/api/event` endpoint.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoPageviews, trackEvent } = Plausible({
domain: 'my-app.com',
apiHost: 'https://stats.my-company.com', // self-hosted Plausible instance
})
enableAutoPageviews()
// Events are sent to: POST https://stats.my-company.com/api/event
// Payload shape: { n: "pageview", u: "https://...", d: "my-app.com", r: null, w: 1280, h: 0 }
```
--------------------------------
### Self-hosted Plausible instance
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Configures the Plausible Tracker to send events to a self-hosted Plausible server instead of the default cloud instance. This is achieved by setting the `apiHost` option during initialization.
```APIDOC
## Self-hosted Plausible instance
### Description
Point the tracker at your own Plausible server by setting `apiHost` at initialization. All events will be POSTed to `{apiHost}/api/event`.
### Configuration
```ts
import Plausible from 'plausible-tracker'
const { enableAutoPageviews, trackEvent } = Plausible({
domain: 'my-app.com',
apiHost: 'https://stats.my-company.com', // self-hosted Plausible instance
})
enableAutoPageviews()
```
### Event Endpoint
- Events are sent to: `POST {apiHost}/api/event`
### Payload Shape Example
```json
{
"n": "pageview",
"u": "https://...",
"d": "my-app.com",
"r": null,
"w": 1280,
"h": 0
}
```
```
--------------------------------
### trackPageview(eventData?, options?)
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Manually sends a 'pageview' event to Plausible. Use this for direct control over when page views are recorded.
```APIDOC
## trackPageview(eventData?, options?)
### Description
Manually sends a `pageview` event to Plausible. Use this when you need direct control over when a page view is recorded, for example after a data fetch resolves or a modal opens.
### Method
`trackPageview`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
#### `eventData` (object, optional)
- `url` (string) - Overrides the current URL for this event.
- `referrer` (string) - Overrides the referrer URL for this event.
- `deviceWidth` (number) - Overrides the device width for this event.
#### `options` (object, optional)
- `callback` (function) - A function to be called after the event is sent, receiving the response status.
### Request Example
```ts
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible({ domain: 'my-app.com' })
// Basic page view — uses current location.href automatically
trackPageview()
// Override URL, referrer, and device width for this specific call
trackPageview({
url: 'https://my-app.com/virtual/checkout-step-2',
referrer: 'https://my-app.com/cart',
deviceWidth: 1440,
})
// With a completion callback
trackPageview(
{ url: 'https://my-app.com/dashboard' },
{
callback: ({ status }) => {
if (status === 202) console.log('Page view accepted by Plausible')
else console.warn('Unexpected status:', status)
},
}
)
```
### Response
#### Success Response (200)
Typically returns a `202 Accepted` status if the event is processed successfully.
#### Response Example
```json
{
"status": 202
}
```
```
--------------------------------
### enableAutoOutboundTracking()
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Automatically tracks clicks on outbound links. It attaches `click` event listeners to all `` tags whose host differs from the current `location.host`. A `MutationObserver` is used to track dynamically added links. Fires an "Outbound Link: Click" event with a `url` prop.
```APIDOC
## enableAutoOutboundTracking(targetNode?, observerInit?)
### Description
Attaches `click` event listeners to all existing `` tags whose `host` differs from `location.host`, and uses a `MutationObserver` to automatically track dynamically added or modified links. Fires an `"Outbound Link: Click"` event with a `url` prop for each click. Returns a cleanup function to remove listeners and disconnect the observer.
### Usage
```ts
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible({ domain: 'my-app.com' })
// Track all outbound links
const cleanup = enableAutoOutboundTracking()
// Scope tracking to a specific container and customize MutationObserver
const container = document.getElementById('content')!
const cleanupScoped = enableAutoOutboundTracking(container, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['href'],
})
// Cleanup
cleanupScoped()
```
### Parameters
- `targetNode` (Node, optional): The DOM node to observe for outbound links.
- `observerInit` (MutationObserverInit, optional): Configuration options for the `MutationObserver`.
### Fires Event
- Event Name: `"Outbound Link: Click"`
- Props: `{ url: string }` where `url` is the `href` of the clicked external link.
### Returns
- `Function`: A cleanup function to remove listeners and disconnect the observer.
```
--------------------------------
### Track a Page View with Plausible Tracker
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Use this snippet to track a single page view. Ensure the Plausible tracker is initialized before calling this function.
```typescript
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible()
// Track a page view
trackPageview()
```
--------------------------------
### enableAutoPageviews()
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Automatically tracks page views on initial load and subsequent navigations in Single Page Applications (SPAs). It hooks into `history.pushState` and `popstate` events. Optionally, it can also track `hashchange` events if `hashMode` is enabled.
```APIDOC
## enableAutoPageviews()
### Description
Tracks the current page view immediately, then hooks into `history.pushState` and the `popstate` event to automatically record page views on every navigation. Optionally tracks `hashchange` events when `hashMode: true` is set. Returns a cleanup function to remove all listeners.
### Usage
```ts
import Plausible from 'plausible-tracker'
// Standard history-based routing
const { enableAutoPageviews } = Plausible({ domain: 'my-app.com' })
const cleanup = enableAutoPageviews()
// Hash-based routing
const { enableAutoPageviews: enableHashTracking } = Plausible({
domain: 'my-app.com',
hashMode: true,
})
const cleanupHash = enableHashTracking()
// Example in a React component
import { useEffect } from 'react'
function App() {
useEffect(() => {
const { enableAutoPageviews } = Plausible({ domain: 'my-app.com' })
const cleanup = enableAutoPageviews()
return cleanup
}, [])
return
}
```
### Returns
- `Function`: A cleanup function to remove all event listeners.
```
--------------------------------
### Track Page View with Callback
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Track a page view and execute a callback function upon completion. This can be used for post-tracking actions or confirmations.
```typescript
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible()
// And override it on this call
trackPageview({}, { callback: () => console.log("Done!") })
```
--------------------------------
### Track Custom Event with Overrides and Callback
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Track a custom event with options to override initialization settings, include properties, and specify a callback function. This offers granular control over event tracking.
```typescript
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible({
trackLocalhost: false,
})
// Tracks the 'signup' goal with a callback, props and a different referrer.
trackEvent(
'signup',
{
callback: () => console.log('done'),
props: {
variation: 'button A'
}
},
{ trackLocalhost: true }
);
```
--------------------------------
### Enable Automatic Page View Tracking with Hash Mode
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Configure automatic page view tracking for SPAs that use URL hashes (`#`) for routing. Set `hashMode` to `true` during initialization.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible({
hashMode: true
})
// Hash changes will also trigger page views
enableAutoPageviews()
```
--------------------------------
### Opt-out via localStorage
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Allows users or developers to suppress all event tracking by setting `localStorage.plausible_ignore` to `"true"`. This is useful for excluding internal traffic or for privacy-conscious users.
```APIDOC
## Opt-out via `localStorage`
### Description
Users or developers can suppress all event tracking by setting `localStorage.plausible_ignore` to `"true"`. This is particularly useful for excluding internal traffic when ad blockers cannot be used.
### Usage
```ts
// Exclude yourself from analytics
localStorage.setItem('plausible_ignore', 'true')
// Re-enable tracking
localStorage.removeItem('plausible_ignore')
// Programmatic check before tracking (optional)
function safeTrack(eventName: string) {
try {
if (localStorage.getItem('plausible_ignore') === 'true') return
} catch {}
trackEvent(eventName)
}
```
### Behavior
- When `localStorage.plausible_ignore` is set to `"true"`, all subsequent `trackEvent` and `trackPageview` calls will be silently ignored.
- The console will log: `[Plausible] Ignoring event because "plausible_ignore" is set to "true" in localStorage`.
```
--------------------------------
### trackEvent(eventName, options?, eventData?)
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Sends a named custom event to Plausible to register goal conversions. Supports custom properties for segmentation.
```APIDOC
## trackEvent(eventName, options?, eventData?)
### Description
Sends a named custom event to Plausible to register goal conversions. The `eventName` must match a goal defined in your Plausible dashboard. Supports custom properties (string, number, or boolean values) for segmented analysis.
### Method
`trackEvent`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
#### `eventName` (string, required)
The name of the custom event or goal to track.
#### `options` (object, optional)
- `props` (object) - Custom properties for segmentation. Values can be strings, numbers, or booleans.
- `callback` (function) - A function to be called after the event is sent, receiving the response status.
#### `eventData` (object, optional)
- `url` (string) - Overrides the current URL for this event.
- `referrer` (string) - Overrides the referrer URL for this event.
- `deviceWidth` (number) - Overrides the device width for this event.
### Request Example
```ts
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible({ domain: 'my-app.com', trackLocalhost: true })
// Simple goal conversion
trackEvent('signup')
// Goal with custom properties for segmentation
trackEvent('purchase', {
props: {
plan: 'pro',
billing_cycle: 'annual',
amount: 99,
trial_converted: true,
},
})
// Goal with callback and per-call URL override
trackEvent(
'video_play',
{
callback: ({ status }) => console.log('Tracked, status:', status),
props: { video_id: 'abc123', quality: '1080p' },
},
{
url: 'https://my-app.com/videos/abc123',
referrer: 'https://my-app.com/home',
}
)
```
### Response
#### Success Response (200)
Typically returns a `202 Accepted` status if the event is processed successfully.
#### Response Example
```json
{
"status": 202
}
```
```
--------------------------------
### Track Custom Event with Properties
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Track custom events and include additional properties for more detailed analytics. Properties can provide context about the event, like the method of download or a specific variation.
```typescript
// Tracks the 'download' goal and provides a 'method' property.
trackEvent('download', { props: { method: 'HTTP' } })
```
--------------------------------
### Enable Automatic Outbound Link Tracking
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Tracks clicks on outbound links (`` tags with different hosts) and dynamically added links using MutationObserver. Fires an 'Outbound Link: Click' event with the URL. Returns a cleanup function.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible({ domain: 'my-app.com' })
// Track all outbound links across the entire document
const cleanup = enableAutoOutboundTracking()
// → Existing links are tracked immediately
// → Dynamically added links are picked up by MutationObserver
// → Clicking a link fires: trackEvent('Outbound Link: Click', { props: { url: 'https://external.com' } })
```
```typescript
// Scope tracking to a specific container and customize MutationObserver
const container = document.getElementById('content')!
const cleanupScoped = enableAutoOutboundTracking(container, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['href'],
})
// Cleanup (e.g., on route change or component teardown)
cleanupScoped()
```
--------------------------------
### enableAutoOutboundTracking
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Enables automatic tracking of clicks on all outbound links on the page. It also handles dynamically added links.
```APIDOC
## enableAutoOutboundTracking
### Description
Automatically tracks clicks on all outbound links (`` tags) on the page. This function also uses a `MutationObserver` to track links added dynamically to the DOM.
### Method
`enableAutoOutboundTracking()`
### Request Example
```javascript
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible()
// Enable automatic tracking for all outbound links
enableAutoOutboundTracking()
```
```
--------------------------------
### Track Custom Events and Goals
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Send a named custom event to Plausible to register goal conversions. The event name must match a goal defined in your Plausible dashboard. Custom properties can be added for segmentation. You can also provide a callback and override URL/referrer per call.
```typescript
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible({ domain: 'my-app.com', trackLocalhost: true })
// Simple goal conversion
trackEvent('signup')
// Goal with custom properties for segmentation
trackEvent('purchase', {
props: {
plan: 'pro',
billing_cycle: 'annual',
amount: 99,
trial_converted: true,
},
})
// Goal with callback and per-call URL override
trackEvent(
'video_play',
{
callback: ({ status }) => console.log('Tracked, status:', status),
props: { video_id: 'abc123', quality: '1080p' },
},
{
url: 'https://my-app.com/videos/abc123',
referrer: 'https://my-app.com/home',
}
)
```
--------------------------------
### enableAutoPageviews
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Enables automatic tracking of page views for Single Page Applications (SPAs). It automatically tracks page views on navigation events and provides a cleanup function.
```APIDOC
## enableAutoPageviews
### Description
Automatically tracks page views for SPAs by listening to browser navigation events. It overrides `history.pushState` and attaches event listeners for `popstate` and `hashchange` (if `hashMode` is true). Returns a cleanup function to remove these listeners.
### Method
`enableAutoPageviews([options])`
### Parameters
#### options
- **hashMode** (boolean) - Optional - Set to `true` if your app uses URL hashes for routing.
### Request Example
```javascript
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible()
// Enable automatic page view tracking
const cleanup = enableAutoPageviews()
// To disable tracking later:
// cleanup()
// Enable automatic page view tracking with hash mode
const { enableAutoPageviews } = Plausible({ hashMode: true })
enableAutoPageviews()
```
```
--------------------------------
### Enable Automatic Outbound Link Tracking
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Automatically track clicks on all outbound links. This function sets up event listeners and a MutationObserver to track both existing and dynamically added links.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible()
// Track all existing and future outbound links
enableAutoOutboundTracking()
```
--------------------------------
### trackEvent
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Tracks a custom event or goal. You can provide custom properties and override tracking options for the event.
```APIDOC
## trackEvent
### Description
Tracks a custom event or goal. This function allows you to send custom event names, associated properties, and override tracking configurations for the specific event.
### Method
`trackEvent(eventName, [eventData], [overrideOptions])`
### Parameters
#### eventName
- **eventName** (string) - Required - The name of the event or goal to track.
#### eventData
- **props** (object) - Optional - An object containing custom properties for the event.
- **callback** (function) - Optional - A callback function to be executed after tracking.
#### overrideOptions
- **trackLocalhost** (boolean) - Optional - Overrides the `trackLocalhost` setting for this specific event.
### Request Example
```javascript
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible()
// Track a simple event
trackEvent('signup')
// Track an event with custom properties
trackEvent('download', { props: { method: 'HTTP' } })
// Track an event with overrides and custom properties
trackEvent(
'signup',
{ props: { variation: 'button A' } },
{ trackLocalhost: true }
);
```
```
--------------------------------
### Manually Track Page View
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Manually send a pageview event. Use this for specific control over tracking, such as after data fetches or modal openings. You can override the URL, referrer, and device width for a specific call. A completion callback can be provided to handle the response status.
```typescript
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible({ domain: 'my-app.com' })
// Basic page view — uses current location.href automatically
trackPageview()
// Override URL, referrer, and device width for this specific call
trackPageview({
url: 'https://my-app.com/virtual/checkout-step-2',
referrer: 'https://my-app.com/cart',
deviceWidth: 1440,
})
// With a completion callback
trackPageview(
{ url: 'https://my-app.com/dashboard' },
{
callback: ({ status }) => {
if (status === 202) console.log('Page view accepted by Plausible')
else console.warn('Unexpected status:', status)
},
}
)
```
--------------------------------
### Track a Custom Event
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Track custom events or goals by providing an event name. This is used for tracking specific user interactions beyond page views, such as button clicks or form submissions.
```typescript
import Plausible from 'plausible-tracker'
const { trackEvent } = Plausible()
// Tracks the 'signup' goal
trackEvent('signup')
```
--------------------------------
### trackPageview
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Tracks a single page view. You can optionally override tracking options or provide event options for this specific call.
```APIDOC
## trackPageview
### Description
Tracks a page view. This function can be called with optional parameters to override default tracking settings or provide additional event data.
### Method
`trackPageview([overrideOptions], [eventOptions])`
### Parameters
#### overrideOptions
- **url** (string) - Optional - The URL of the current page.
- **referrer** (string or null) - Optional - The referrer's address.
- **deviceWidth** (number) - Optional - The user's device width for device tracking.
#### eventOptions
- **callback** (function) - Optional - A callback function to be executed after tracking.
### Request Example
```javascript
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible()
// Track a page view with default options
trackPageview()
// Track a page view with overridden URL and trackLocalhost setting
trackPageview({
url: "https://my-app.com/my-url",
trackLocalhost: false
})
// Track a page view with a callback function
trackPageview({}, { callback: () => console.log("Done!") })
```
```
--------------------------------
### Override Page View Tracking Options
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Override default tracking options like `trackLocalhost` or specify a custom `url` for a specific page view. This is useful for testing or when the default `location.href` is not desired.
```typescript
import Plausible from 'plausible-tracker'
const { trackPageview } = Plausible({
// Track localhost by default
trackLocalhost: true,
})
// Override it on this call and also set a custom url
trackPageview({
trackLocalhost: false,
url: "https://my-app.com/my-url"
})
```
--------------------------------
### Enable Automatic SPA Page View Tracking
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Automatically tracks page views in Single Page Applications by hooking into history API changes. Supports both standard history routing and hash-based routing. Returns a cleanup function to remove listeners.
```typescript
import Plausible from 'plausible-tracker'
// Standard history-based routing (React Router, Vue Router, etc.)
const { enableAutoPageviews } = Plausible({ domain: 'my-app.com' })
const cleanup = enableAutoPageviews()
// → Fires a pageview immediately for the landing page
// → Fires a pageview on every history.pushState / popstate
```
```typescript
// Hash-based routing (e.g., /#/about, /#/contact)
const { enableAutoPageviews: enableHashTracking } = Plausible({
domain: 'my-app.com',
hashMode: true,
})
const cleanupHash = enableHashTracking()
// → Also fires on hashchange events
```
```typescript
// In a React component with cleanup on unmount
import { useEffect } from 'react'
function App() {
useEffect(() => {
const { enableAutoPageviews } = Plausible({ domain: 'my-app.com' })
const cleanup = enableAutoPageviews()
return cleanup // called on component unmount
}, [])
return
}
```
--------------------------------
### Enable and Disable Auto Outbound Tracking
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Call the returned cleanup function to remove event listeners and disconnect the MutationObserver initialized by enableAutoOutboundTracking().
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoOutboundTracking } = Plausible()
const cleanup = enableAutoOutboundTracking()
// ...
// Remove event listeners and disconnect the MutationObserver
cleanup()
```
--------------------------------
### Opt-out of Tracking via localStorage
Source: https://context7.com/plausible/plausible-tracker/llms.txt
Suppresses all event tracking by setting `localStorage.plausible_ignore` to 'true'. Useful for excluding internal traffic. Tracking can be re-enabled by removing the item.
```javascript
// Exclude yourself (developer/admin) from analytics
localStorage.setItem('plausible_ignore', 'true')
// → All subsequent trackEvent / trackPageview calls will be silently ignored
// → Console will log: [Plausible] Ignoring event because "plausible_ignore" is set to "true" in localStorage
// Re-enable tracking
localStorage.removeItem('plausible_ignore')
```
```javascript
// Programmatic check before tracking (optional)
function safeTrack(eventName: string) {
try {
if (localStorage.getItem('plausible_ignore') === 'true') return
} catch {}
trackEvent(eventName)
}
```
--------------------------------
### Clean Up Auto Page View Event Listeners
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Call the cleanup function returned by `enableAutoPageviews()` to remove event listeners and restore `history.pushState`. This is important for preventing memory leaks or unintended behavior when disabling auto-tracking.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible()
const cleanup = enableAutoPageviews()
// ...
// Remove event listeners and restore history.pushState
cleanup()
```
--------------------------------
### Enable Automatic Page View Tracking
Source: https://github.com/plausible/plausible-tracker/blob/master/README.md
Automatically track page views in Single Page Applications (SPAs). This function hooks into browser navigation events to track route changes.
```typescript
import Plausible from 'plausible-tracker'
const { enableAutoPageviews } = Plausible()
// This tracks the current page view and all future ones as well
enableAutoPageviews()
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.