Skip to content

Commit 3ea26f9

Browse files
committedAug 6, 2024·
fix: correctly allow empty ignoredHostnames array to exclude localhost (fixes #30)
1 parent a83fb35 commit 3ea26f9

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export default defineNuxtConfig({
5151
})
5252
```
5353

54+
> [!TIP]
55+
> To allow tracking events on localhost, set the `ignoredHostnames` option to an empty array.
56+
5457
### Runtime Config
5558

5659
Alternatively, leveraging [automatically replaced public runtime config values](https://nuxt.com/docs/api/configuration/nuxt-config#runtimeconfig) by matching environment variables at runtime, set your desired option in your project's `.env` file:

‎src/module.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default defineNuxtModule<ModuleOptions>({
105105
enabled: true,
106106
hashMode: false,
107107
domain: '',
108-
ignoredHostnames: [],
108+
ignoredHostnames: undefined,
109109
ignoreSubDomains: false,
110110
trackLocalhost: false,
Has conversations. Original line has conversations.
111111
apiHost: 'https://plausible.io',
@@ -117,14 +117,12 @@ export default defineNuxtModule<ModuleOptions>({
117117
const logger = useLogger('plausible')
118118
const { resolve } = createResolver(import.meta.url)
119119

120+
// Set default hostnames if `ignoredHostnames` is not set
121+
options.ignoredHostnames ??= [...DEFAULT_HOSTNAMES]
122+
120123
// Dedupe `ignoredHostnames` items
121124
options.ignoredHostnames = Array.from(new Set(options.ignoredHostnames))
122125

123-
// Add default hostnames if `ignoredHostnames` is empty
124-
if (options.ignoredHostnames.length === 0) {
125-
options.ignoredHostnames = DEFAULT_HOSTNAMES
126-
}
127-
128126
// Migrate `trackLocalhost` to `ignoredHostnames`
129127
if (options.trackLocalhost) {
130128
logger.warn('The `trackLocalhost` option has been deprecated. Please use `ignoredHostnames` instead.')

0 commit comments

Comments
 (0)
Please sign in to comment.