@arthurreira/analytics 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +2 -3
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { usePathname } from 'next/navigation';
|
|
3
2
|
|
|
4
3
|
// src/lib/api.ts
|
|
5
4
|
var BASE_FIELDS = (sessionId, eventType, path) => ({
|
|
@@ -131,14 +130,14 @@ function useAnalytics(apiUrl, apiKey) {
|
|
|
131
130
|
|
|
132
131
|
// src/components/Analytics.tsx
|
|
133
132
|
function Analytics({ apiKey, apiUrl }) {
|
|
134
|
-
const pathname = usePathname();
|
|
135
133
|
const { trackPageview: trackPageview2 } = useAnalytics(apiUrl, apiKey);
|
|
136
134
|
const lastTracked = useRef(null);
|
|
135
|
+
const pathname = typeof window !== "undefined" ? window.location.pathname : "";
|
|
137
136
|
useEffect(() => {
|
|
138
137
|
if (lastTracked.current === pathname) return;
|
|
139
138
|
lastTracked.current = pathname;
|
|
140
139
|
trackPageview2(pathname);
|
|
141
|
-
}, [pathname]);
|
|
140
|
+
}, [pathname, trackPageview2]);
|
|
142
141
|
return null;
|
|
143
142
|
}
|
|
144
143
|
|