Skip to content

Commit

Permalink
Merge branch 'main' into v4-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich authored Jun 20, 2024
2 parents c17f3f7 + ebdf9ed commit 5183664
Show file tree
Hide file tree
Showing 25 changed files with 7,919 additions and 4,025 deletions.
20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

55 changes: 14 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,26 @@ on:
- main

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- run: corepack enable

- name: Install
run: pnpm i

- name: Lint
run: pnpm run format:check

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: 18

- run: corepack enable

- name: Install
run: pnpm i

- name: Lint
run: pnpm run lint
node-version: 20
- run: pnpm install
- run: pnpm run dev:prepare
- run: pnpm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: 18

- run: corepack enable

- name: Install
run: pnpm i

- name: Typecheck
run: pnpm run test:types
node-version: 20
- run: pnpm install
- run: pnpm run dev:prepare
- run: pnpm run test:types
18 changes: 10 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
registry-url: https://registry.npmjs.org/

- run: corepack enable

- run: npx changelogithub
- name: Publish changelog
run: npx changelogithub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install
run: pnpm i
run: pnpm install

- name: Build type stubs
run: pnpm run dev:prepare

- name: Publish to npm
run: npm publish --access public
Expand Down
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
shamefully-hoist=true
strict-peer-dependencies=false
1 change: 0 additions & 1 deletion .nuxtrc

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"Vue.volar"
]
}
41 changes: 37 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
{
// Enable the ESLint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use ESLint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto-fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.validate": ["javascript", "javascriptreact", "vue"]

// Silent the stylistic rules in you IDE, but still auto-fix them
"eslint.rules.customizations": [
{ "rule": "@stylistic/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable ESLint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml"
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2023 Johann Schopplich <https://github.com/johannschopplich>
Copyright (c) 2022-PRESENT Johann Schopplich <https://github.com/johannschopplich>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![npm version](https://img.shields.io/npm/v/@nuxtjs/plausible?color=a1b858&label=)](https://www.npmjs.com/package/@nuxtjs/plausible)

> [Nuxt 3](https://nuxt.com) module to integrate the [Plausible tracker](https://github.com/plausible/plausible-tracker).
Native integration of [Plausible Analytics](https://plausible.io/sites) for [Nuxt](https://nuxt.com).

## Features

Expand All @@ -17,11 +17,7 @@
## Setup

```bash
# pnpm
pnpm add -D @nuxtjs/plausible

# npm
npm i -D @nuxtjs/plausible
npx nuxi@latest module add plausible
```

## Basic Usage
Expand All @@ -37,7 +33,8 @@ export default defineNuxtConfig({

Done! Plausible will now run in your application's client.

> ℹ️ By default, `@nuxtjs/plausible` will use `window.location.hostname` for the Plausible `domain` configuration key, which will suit most users.
> [!TIP]
> 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 @@ -48,7 +45,8 @@ export default defineNuxtConfig({
modules: ['@nuxtjs/plausible'],

plausible: {
domain: 'example.com',
// Prevent tracking on localhost
ignoredHostnames: ['localhost'],
},
})
```
Expand All @@ -66,20 +64,24 @@ With this setup, you can omit the `plausible` key in your Nuxt configuration.

## Module Options

| Option | Type | Default | Description |
| ---------------------- | --------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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. |
| `trackLocalhost` | `boolean` | `false` | Whether events shall be tracked when running the site locally. |
| `domain` | `string` | `'window.location.hostname'` | The domain to bind tracking event to. |
| `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. |
| 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](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.
> [!NOTE]
> Since the Plausible instance is available in the client only, executing the composables on the server will have no effect.
### `useTrackEvent`

Expand Down Expand Up @@ -128,10 +130,10 @@ function useTrackPageview(
4. Run `pnpm run dev:prepare`
5. Start development server using `pnpm run dev`

## Similar Packages
## Credits

- [vue-plausible](https://github.com/moritzsternemann/vue-plausible), without first-class Nuxt 3 and composables.
- [@Barbapapazes](https://github.com/Barbapapazes) for his [Plausible tracker rewrite](https://github.com/Barbapapazes/plausible-tracker)

## License

[MIT](./LICENSE) License © 2022-2023 [Johann Schopplich](https://github.com/johannschopplich)
[MIT](./LICENSE) License © 2022-PRESENT [Johann Schopplich](https://github.com/johannschopplich)
11 changes: 11 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

export default createConfigForNuxt({
features: {
tooling: true,
stylistic: true,
},
dirs: {
src: ['./playground'],
},
})
49 changes: 21 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@nuxtjs/plausible",
"type": "module",
"version": "0.2.3",
"packageManager": "pnpm@8.7.4",
"description": "Nuxt 3 module to natively integrate Plausible analytics",
"author": "Johann Schopplich <pkg@johannschopplich.com>",
"version": "1.0.0",
"packageManager": "pnpm@9.0.6",
"description": "Natively integrates Plausible Analytics into Nuxt",
"author": "Johann Schopplich <hello@johannschopplich.com>",
"license": "MIT",
"homepage": "https://github.com/nuxt-modules/plausible#readme",
"repository": {
Expand All @@ -13,10 +13,10 @@
},
"bugs": "https://github.com/nuxt-modules/plausible/issues",
"keywords": [
"analytics",
"nuxt",
"nuxt3",
"plausible",
"analytics"
"plausible"
],
"exports": {
".": {
Expand All @@ -31,36 +31,29 @@
"dist"
],
"scripts": {
"prepack": "nuxt-module-build",
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test:types": "tsc --noEmit",
"format": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --write",
"format:check": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --check",
"release": "bumpp --commit --push --tag",
"prepare": "nuxi prepare playground"
"release": "bumpp"
},
"dependencies": {
"@nuxt/kit": "^3.7.1",
"defu": "^6.1.2",
"pathe": "^1.1.1",
"plausible-tracker": "^0.3.8"
"@barbapapazes/plausible-tracker": "^0.5.0",
"@nuxt/kit": "^3.11.2",
"defu": "^6.1.4"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/module-builder": "^0.5.1",
"@nuxt/schema": "^3.7.1",
"@nuxtjs/plausible": "workspace:*",
"@types/node": "^20.5.9",
"bumpp": "^9.2.0",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"nuxt": "^3.7.1",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vue-tsc": "^1.8.10"
"@nuxt/eslint-config": "0.3.0-beta.9",
"@nuxt/module-builder": "^0.6.0",
"@nuxt/schema": "^3.11.2",
"@types/node": "^20.12.7",
"bumpp": "^9.4.1",
"eslint": "^9.1.1",
"nuxt": "^3.11.2",
"typescript": "^5.4.5",
"vue-tsc": "^2.0.15"
}
}
Loading

0 comments on commit 5183664

Please sign in to comment.