From 7fc690f021a4c6df3b513e8d62dc348aa2e38d7b Mon Sep 17 00:00:00 2001 From: AtaS Date: Mon, 21 Oct 2024 22:12:31 +0100 Subject: [PATCH] Run Matomo pageview tracking only when url changes --- .eslintrc.js | 10 ++++----- package-lock.json | 42 +++++++++++++++++++++++++---------- package.json | 1 + src/hooks/PageViewTracking.ts | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f71ea26..dd8f5bf 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { createClass: 'createReactClass', // Regex for Component Factory to use, // default to "createReactClass" pragma: 'React', // Pragma to use, default to "React" - fragment: 'Fragment', // Fragment to use (maybe a property of ), default to "Fragment" + fragment: 'Fragment', // Fragment to use (may be a property of ), default to "Fragment" version: 'detect', // React version. "detect" automatically picks the version you have installed. }, propWrapperFunctions: [ @@ -45,12 +45,12 @@ module.exports = { }, ecmaVersion: 2018, sourceType: 'module', - tsconfigRootDir: __dirname, - project: './tsconfig.eslint.json', + project: './tsconfig.json', }, - plugins: ['react', '@typescript-eslint', 'promise'], + plugins: ['react', '@typescript-eslint', 'promise', 'unused-imports'], rules: { - indent: ['error', 'tab'], + 'unused-imports/no-unused-imports': 'error', + indent: ['error', 'tab', { SwitchCase: 1 }], 'no-tabs': 0, semi: 'off', 'require-await': 'off', // disabled in favour of @typescript-eslint/require-await diff --git a/package-lock.json b/package-lock.json index fee8555..265d301 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-promise": "^6.2.0", "eslint-plugin-react": "^7.34.3", + "eslint-plugin-unused-imports": "^4.1.4", "jest": "^29.7.0", "npm-check": "^6.0.1", "prettier": "^3.3.2", @@ -3061,9 +3062,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz", + "integrity": "sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==", "dev": true, "license": "MIT", "engines": { @@ -3658,14 +3659,14 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz", + "integrity": "sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==", "deprecated": "Use @eslint/config-array instead", "dev": true, "license": "Apache-2.0", "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", + "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", "minimatch": "^3.0.5" }, @@ -7048,17 +7049,18 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz", + "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", + "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint/js": "8.57.1", + "@humanwhocodes/config-array": "^0.13.0", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "@ungap/structured-clone": "^1.2.0", @@ -7656,6 +7658,22 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.4.tgz", + "integrity": "sha512-YptD6IzQjDardkl0POxnnRBhU1OEePMV0nd6siHaRBbd+lyh6NAhFEobiznKU7kTsSsDeSD62Pe7kAM1b7dAZQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0", + "eslint": "^9.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", diff --git a/package.json b/package.json index dd075d6..dd34ca5 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-promise": "^6.2.0", "eslint-plugin-react": "^7.34.3", + "eslint-plugin-unused-imports": "^4.1.4", "jest": "^29.7.0", "npm-check": "^6.0.1", "prettier": "^3.3.2", diff --git a/src/hooks/PageViewTracking.ts b/src/hooks/PageViewTracking.ts index 9b91476..3ce2384 100644 --- a/src/hooks/PageViewTracking.ts +++ b/src/hooks/PageViewTracking.ts @@ -15,7 +15,7 @@ export const useMatomoPageView = () => { _paq.push(['setCustomUrl', window.location.href]); _paq.push(['trackPageView']); } - }, [location]); + }, [location.pathname.toString(), location.search.toString()]); }; /**