@arthurreira/analytics 0.10.0 → 0.11.0

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.
Files changed (2) hide show
  1. package/dist/client.js +3 -1
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -201,6 +201,7 @@ function useAnalytics(apiUrl, apiKey, options) {
201
201
  const pendingEvents = useRef([]);
202
202
  const pathname = useRef(typeof window !== "undefined" ? window?.location?.pathname ?? "" : "");
203
203
  const presence = useRef(null);
204
+ const hasSentEnd = useRef(false);
204
205
  useEffect(() => {
205
206
  if (typeof window === "undefined") return;
206
207
  const visitor_id = localStorage.getItem("af_analytics_visitor_id") || crypto.randomUUID();
@@ -220,7 +221,8 @@ function useAnalytics(apiUrl, apiKey, options) {
220
221
  useEffect(() => {
221
222
  if (typeof window === "undefined") return;
222
223
  const sendEnd = () => {
223
- if (!sessionId.current) return;
224
+ if (!sessionId.current || hasSentEnd.current) return;
225
+ hasSentEnd.current = true;
224
226
  presence.current?.disconnect();
225
227
  presence.current = null;
226
228
  navigator.sendBeacon(`${apiUrl}/sessions/${sessionId.current}/end`);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "@arthurreira/analytics",
2
- "version": "0.10.0",
2
+ "version": "0.11.0",
3
3
  "type": "module",
4
4
  "scripts": {
5
5
  "build": "tsup",