@devskin/browser-sdk 1.0.25 → 1.0.26
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/devskin.cjs.js +41 -10
- package/dist/devskin.cjs.js.map +1 -1
- package/dist/devskin.esm.js +41 -10
- package/dist/devskin.esm.js.map +1 -1
- package/dist/devskin.umd.js +41 -10
- package/dist/devskin.umd.js.map +1 -1
- package/dist/devskin.umd.min.js +2 -2
- package/dist/devskin.umd.min.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/recorder/session.d.ts +0 -18
- package/dist/recorder/session.d.ts.map +0 -1
package/dist/devskin.esm.js
CHANGED
|
@@ -14060,11 +14060,32 @@ class DevSkinSDK {
|
|
|
14060
14060
|
* Private methods
|
|
14061
14061
|
*/
|
|
14062
14062
|
startSession() {
|
|
14063
|
-
var _a;
|
|
14063
|
+
var _a, _b, _c;
|
|
14064
|
+
// Check if there's an active session (stored in sessionStorage to persist across page navigations)
|
|
14065
|
+
const existingSessionId = sessionStorage.getItem('devskin_session_id');
|
|
14066
|
+
const existingSessionStart = sessionStorage.getItem('devskin_session_start');
|
|
14067
|
+
if (existingSessionId && existingSessionStart) {
|
|
14068
|
+
// Resume existing session
|
|
14069
|
+
this.sessionId = existingSessionId;
|
|
14070
|
+
this.sessionStartTime = parseInt(existingSessionStart, 10);
|
|
14071
|
+
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
14072
|
+
console.log('[DevSkin] Resuming existing session:', this.sessionId);
|
|
14073
|
+
}
|
|
14074
|
+
// Send page view but DON'T create a new session
|
|
14075
|
+
// The session is already created, just continue it
|
|
14076
|
+
return;
|
|
14077
|
+
}
|
|
14078
|
+
// Create new session
|
|
14064
14079
|
this.sessionId = this.generateId();
|
|
14065
14080
|
this.sessionStartTime = Date.now();
|
|
14081
|
+
// Store in sessionStorage (persists across page navigations in same tab)
|
|
14082
|
+
sessionStorage.setItem('devskin_session_id', this.sessionId);
|
|
14083
|
+
sessionStorage.setItem('devskin_session_start', this.sessionStartTime.toString());
|
|
14066
14084
|
const sessionData = Object.assign({ session_id: this.sessionId, user_id: this.userId || undefined, anonymous_id: this.anonymousId, started_at: new Date().toISOString() }, this.getContextData());
|
|
14067
|
-
(
|
|
14085
|
+
(_b = this.transport) === null || _b === void 0 ? void 0 : _b.startSession(sessionData);
|
|
14086
|
+
if ((_c = this.config) === null || _c === void 0 ? void 0 : _c.debug) {
|
|
14087
|
+
console.log('[DevSkin] New session created:', this.sessionId);
|
|
14088
|
+
}
|
|
14068
14089
|
}
|
|
14069
14090
|
getContextData() {
|
|
14070
14091
|
const context = {};
|
|
@@ -14101,16 +14122,26 @@ class DevSkinSDK {
|
|
|
14101
14122
|
});
|
|
14102
14123
|
}
|
|
14103
14124
|
setupUnloadTracking() {
|
|
14104
|
-
|
|
14125
|
+
// Use pagehide event which is more reliable than beforeunload
|
|
14126
|
+
window.addEventListener('pagehide', (event) => {
|
|
14105
14127
|
var _a, _b;
|
|
14106
|
-
|
|
14107
|
-
//
|
|
14108
|
-
|
|
14109
|
-
|
|
14110
|
-
|
|
14111
|
-
|
|
14128
|
+
// Only end session if tab is actually closing (not just navigating)
|
|
14129
|
+
// persisted = false means the page is going into bfcache (navigation)
|
|
14130
|
+
// persisted = true OR event doesn't exist means actual close
|
|
14131
|
+
const isActualClose = !event.persisted;
|
|
14132
|
+
if (isActualClose) {
|
|
14133
|
+
this.track('page_unload');
|
|
14134
|
+
// Only send session end if tab is actually closing
|
|
14135
|
+
if (this.sessionId && this.sessionStartTime) {
|
|
14136
|
+
const endedAt = new Date();
|
|
14137
|
+
const durationMs = Date.now() - this.sessionStartTime;
|
|
14138
|
+
(_a = this.transport) === null || _a === void 0 ? void 0 : _a.startSession(Object.assign({ session_id: this.sessionId, user_id: this.userId || undefined, anonymous_id: this.anonymousId, ended_at: endedAt.toISOString(), duration_ms: durationMs }, this.getContextData()));
|
|
14139
|
+
// Clear session storage since session is ending
|
|
14140
|
+
sessionStorage.removeItem('devskin_session_id');
|
|
14141
|
+
sessionStorage.removeItem('devskin_session_start');
|
|
14142
|
+
}
|
|
14112
14143
|
}
|
|
14113
|
-
//
|
|
14144
|
+
// Always flush pending data (whether navigation or close)
|
|
14114
14145
|
(_b = this.transport) === null || _b === void 0 ? void 0 : _b.flush(true); // Use beacon for reliability
|
|
14115
14146
|
});
|
|
14116
14147
|
}
|