Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@nuxtjs/plausible
Advanced tools
Native integration of Plausible Analytics for Nuxt.
.env
file supportnpx nuxi@latest module add plausible
Add @nuxtjs/plausible
to the modules
section of your Nuxt configuration:
// `nuxt.config.ts`
export default defineNuxtConfig({
modules: ['@nuxtjs/plausible'],
})
Done! Plausible will now run in your application's client.
[!TIP] By default,
@nuxtjs/plausible
will usewindow.location.hostname
for the Plausibledomain
configuration key, which should suit most use-cases. If you need to customize the domain, you can do so in the module options.
All supported module options can be configured using the plausible
key in your Nuxt configuration:
export default defineNuxtConfig({
modules: ['@nuxtjs/plausible'],
plausible: {
// Prevent tracking on localhost
ignoredHostnames: ['localhost'],
},
})
[!TIP] To allow tracking events on localhost, set the
ignoredHostnames
option to an empty array.
Alternatively, leveraging automatically replaced public runtime config values by matching environment variables at runtime, set your desired option in your project's .env
file:
# Sets the `plausible.domain` option to `example.com`
NUXT_PUBLIC_PLAUSIBLE_DOMAIN=example.com
With this setup, you can omit the plausible
key in your Nuxt configuration.
The module provides a proxy API feature that allows you to route Plausible events through your Nitro server instead of sending them directly to Plausible's servers. This is useful if you want to prevent ad blockers from blocking requests to Plausible's domain. When proxy is enabled, the tracker will automatically route requests through the current origin.
To enable the proxy API, set the proxy
option to true
:
export default defineNuxtConfig({
modules: ['@nuxtjs/plausible'],
plausible: {
proxy: true,
},
})
[!NOTE] When enabled, all Plausible events will be sent to your server first, which then forwards them to Plausible's API. The default proxy endpoint is
/_plausible
, but you can customize the path using theproxyBaseEndpoint
module option.
Option | Type | Default | Description |
---|---|---|---|
enabled | boolean | true | Whether the tracker shall be enabled. |
hashMode | boolean | false | Whether page views shall be tracked when the URL hash changes. Enable this if your Nuxt app uses the hashMode router option instead of the default history mode. |
domain | string | 'window.location.hostname' | The domain to bind tracking event to. |
ignoredHostnames | string[] | ['localhost'] | Hostnames to ignore when tracking events. |
ignoreSubDomains | boolean | false | Ignore the hostname if it is a subdomain of ignoredHostnames . |
apiHost | string | https://plausible.io | The API host where the events will be sent to. |
autoPageviews | boolean | true | Track the current page and all further pages automatically. Disable this if you want to manually manage pageview tracking. |
autoOutboundTracking | boolean | false | Track all outbound link clicks automatically. If enabled, a MutationObserver automagically detects link nodes throughout the application and binds click events to them. |
logIgnoredEvents | boolean | false | Log events to the console if they are ignored. |
proxy | boolean | false | Whether to proxy the event endpoint through the current origin. |
proxyBaseEndpoint | string | '/_plausible' | The base endpoint to proxy the Plausible event endpoint through. |
As with other composables in the Nuxt ecosystem, they are auto-imported and can be used in your application's components.
[!NOTE] Since the Plausible instance is available in the client only, executing the composables on the server will have no effect.
useTrackEvent
Track a custom event. Track your defined goals by passing the goal's name as the argument eventName
.
Type Declarations
function useTrackEvent(
eventName: string,
options?: EventOptions,
eventData?: PlausibleOptions,
): void
Example
// Tracks the `signup` goal
useTrackEvent('signup')
// Tracks the `Download` goal passing a `method` property.
useTrackEvent('Download', { props: { method: 'HTTP' } })
useTrackPageview
Manually track a page view.
Pass optional event data to be sent with the eventData
argument. Defaults to the current page's data merged with the default options provided during the Plausible initialization.
Type Declarations
function useTrackPageview(
eventData?: PlausibleOptions,
options?: EventOptions,
): void
corepack enable
pnpm install
pnpm run dev:prepare
pnpm run dev
MIT License © 2022-PRESENT Johann Schopplich
FAQs
Natively integrates Plausible Analytics into Nuxt
The npm package @nuxtjs/plausible receives a total of 2,530 weekly downloads. As such, @nuxtjs/plausible popularity was classified as popular.
We found that @nuxtjs/plausible demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.