Skip to content

Commit 3d7a9f1

Browse files
fix: auto-importable composables even if tracker is disabled
1 parent 305d41d commit 3d7a9f1

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ With this setup, you can omit the `plausible` key in your Nuxt configuration.
6767
| Option | Type | Default | Description |
6868
| ---------------------- | ---------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6969
| `enabled` | `boolean` | `true` | Whether the tracker shall be enabled. |
70-
| `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. |
70+
| `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. |
7171
| `domain` | `string` | `'window.location.hostname'` | The domain to bind tracking event to. |
7272
| `ignoredHostnames` | `string[]` | `['localhost']` | Hostnames to ignore when tracking events. |
7373
| `apiHost` | `string` | `https://plausible.io` | The API host where the events will be sent to. |

src/module.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ export default defineNuxtModule<ModuleOptions>({
126126
options,
127127
)
128128

129-
if (!options.enabled) {
130-
return
131-
}
132-
133129
// Transpile runtime
134130
nuxt.options.build.transpile.push(resolve('runtime'))
135131

src/runtime/composables/useTrackEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import type {
2121
export function useTrackEvent(eventName: EventName, options?: EventOptions) {
2222
if (import.meta.client) {
2323
// eslint-disable-next-line no-extra-semi
24-
;(useNuxtApp().$plausible as Plausible).trackEvent(eventName, options)
24+
;(useNuxtApp().$plausible as Plausible)?.trackEvent(eventName, options)
2525
}
2626
}

src/runtime/composables/useTrackPageview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import type { EventOptions, Plausible } from '@barbapapazes/plausible-tracker'
1313
export function useTrackPageview(options?: EventOptions) {
1414
if (import.meta.client) {
1515
// eslint-disable-next-line no-extra-semi
16-
;(useNuxtApp().$plausible as Plausible).trackPageview(options)
16+
;(useNuxtApp().$plausible as Plausible)?.trackPageview(options)
1717
}
1818
}

0 commit comments

Comments
 (0)