Skip to content

Commit

Permalink
fix: auto-importable composables even if tracker is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Apr 3, 2024
1 parent 305d41d commit 3d7a9f1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ With this setup, you can omit the `plausible` key in your Nuxt configuration.
| 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 has the `hashMode` router option 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. |
| `apiHost` | `string` | `https://plausible.io` | The API host where the events will be sent to. |
Expand Down
4 changes: 0 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ export default defineNuxtModule<ModuleOptions>({
options,
)

if (!options.enabled) {
return
}

// Transpile runtime
nuxt.options.build.transpile.push(resolve('runtime'))

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/useTrackEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import type {
export function useTrackEvent(eventName: EventName, options?: EventOptions) {
if (import.meta.client) {
// eslint-disable-next-line no-extra-semi
;(useNuxtApp().$plausible as Plausible).trackEvent(eventName, options)
;(useNuxtApp().$plausible as Plausible)?.trackEvent(eventName, options)
}
}
2 changes: 1 addition & 1 deletion src/runtime/composables/useTrackPageview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import type { EventOptions, Plausible } from '@barbapapazes/plausible-tracker'
export function useTrackPageview(options?: EventOptions) {
if (import.meta.client) {
// eslint-disable-next-line no-extra-semi
;(useNuxtApp().$plausible as Plausible).trackPageview(options)
;(useNuxtApp().$plausible as Plausible)?.trackPageview(options)
}
}

0 comments on commit 3d7a9f1

Please sign in to comment.