diff --git a/core-web/libs/sdk/analytics/.eslintrc.json b/core-web/libs/sdk/analytics/.eslintrc.json index 4cfe38bd218..dbfa53a7b14 100644 --- a/core-web/libs/sdk/analytics/.eslintrc.json +++ b/core-web/libs/sdk/analytics/.eslintrc.json @@ -18,7 +18,15 @@ "files": ["*.json"], "parser": "jsonc-eslint-parser", "rules": { - "@nx/dependency-checks": "error" + "@nx/dependency-checks": [ + "error", + { + "ignoredDependencies": [ + "@testing-library/jest-dom", + "@testing-library/react" + ] + } + ] } } ] diff --git a/core-web/libs/sdk/analytics/package.json b/core-web/libs/sdk/analytics/package.json index 63269b2defe..0f52e194185 100644 --- a/core-web/libs/sdk/analytics/package.json +++ b/core-web/libs/sdk/analytics/package.json @@ -22,12 +22,15 @@ "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/analytics/README.md", "dependencies": { "analytics": "^0.8.14", - "vite": "~5.0.0", - "@testing-library/jest-dom": "^6.1.6" + "vite": "~5.0.0" }, "peerDependencies": { "react": "^18.2.0" }, + "devDependencies": { + "@testing-library/jest-dom": "^6.1.6", + "@testing-library/react": "^14.0.0" + }, "main": "./index.cjs.js", "module": "./index.esm.js", "exports": { diff --git a/core-web/libs/sdk/analytics/src/lib/react/hook/useRouterTracker.ts b/core-web/libs/sdk/analytics/src/lib/react/hook/useRouterTracker.ts index 23f9b2d8368..1b24d5fa27f 100644 --- a/core-web/libs/sdk/analytics/src/lib/react/hook/useRouterTracker.ts +++ b/core-web/libs/sdk/analytics/src/lib/react/hook/useRouterTracker.ts @@ -18,9 +18,9 @@ export function useRouterTracker(analytics: DotContentAnalytics | null) { function handleRouteChange() { const currentPath = window.location.pathname; - if (currentPath !== lastPathRef.current && !isInsideEditor()) { + if (currentPath !== lastPathRef.current && !isInsideEditor() && analytics) { lastPathRef.current = currentPath; - analytics!.pageView(); + analytics.pageView(); } }