Skip to content

Commit

Permalink
refactor: tracker implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Feb 23, 2024
1 parent 5e72535 commit 267eb76
Show file tree
Hide file tree
Showing 5 changed files with 804 additions and 776 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineNuxtConfig({
Done! Plausible will now run in your application's client.

> [!TIP]
> By default, `@nuxtjs/plausible` will use `window.location.hostname` for the Plausible `domain` configuration key, which should suit most users.
> By default, `@nuxtjs/plausible` will use `window.location.hostname` for the Plausible `domain` configuration key, which should suit most use-cases. If you need to customize the domain, you can do so in the [module options](#module-options).
## Configuration

Expand All @@ -49,7 +49,8 @@ export default defineNuxtConfig({
modules: ['@nuxtjs/plausible'],

plausible: {
domain: 'example.com',
// Prevent tracking on localhost
ignoredHostnames: ['localhost'],
},
})
```
Expand All @@ -71,18 +72,19 @@ With this setup, you can omit the `plausible` key in your Nuxt configuration.
| ---------------------- | ---------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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. |
| `ignoredHostnames` | `string[]` | `undefined` | Hostnames to ignore when tracking events. |
| `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. |
| `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](https://developer.mozilla.org/en-US/docs/Web/API/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. |

## Composables

As with other composables in the Nuxt 3 ecosystem, they are auto-imported and can be used in your application's components.
As with other composables in the Nuxt ecosystem, they are auto-imported and can be used in your application's components.

> ℹ️ Since the Plausible instance is available in the client only, executing the composables on the server will have no effect.
> [!INFO]
> Since the Plausible instance is available in the client only, executing the composables on the server will have no effect.
### `useTrackEvent`

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nuxtjs/plausible",
"type": "module",
"version": "0.2.4",
"packageManager": "pnpm@8.15.1",
"packageManager": "pnpm@8.15.3",
"description": "Natively integrates Plausible Analytics into Nuxt",
"author": "Johann Schopplich <pkg@johannschopplich.com>",
"license": "MIT",
Expand Down Expand Up @@ -43,19 +43,19 @@
"release": "bumpp --commit --push --tag"
},
"dependencies": {
"@barbapapazes/plausible-tracker": "^0.3.1",
"@nuxt/kit": "^3.10.0",
"@barbapapazes/plausible-tracker": "^0.4.0",
"@nuxt/kit": "^3.10.3",
"defu": "^6.1.4"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.10.0",
"@types/node": "^20.11.16",
"@nuxt/schema": "^3.10.3",
"@types/node": "^20.11.20",
"bumpp": "^9.3.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"nuxt": "^3.10.0",
"nuxt": "^3.10.3",
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vue-tsc": "^1.8.27"
Expand Down

0 comments on commit 267eb76

Please sign in to comment.