posthog-js 1.30.0 → 1.31.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.
- package/CHANGELOG.md +5 -0
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +48 -7
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +2 -0
- package/dist/module.js +48 -7
- package/dist/module.js.map +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/dist/module.d.ts
CHANGED
|
@@ -818,6 +818,7 @@ declare class SessionIdManager {
|
|
|
818
818
|
_windowId: string | null | undefined;
|
|
819
819
|
_sessionId: string | null | undefined;
|
|
820
820
|
window_id_storage_key: string;
|
|
821
|
+
primary_window_exists_storage_key: string;
|
|
821
822
|
_sessionStartTimestamp: number | null;
|
|
822
823
|
_sessionActivityTimestamp: number | null;
|
|
823
824
|
constructor(config: Partial<PostHogConfig>, persistence: PostHogPersistence);
|
|
@@ -826,6 +827,7 @@ declare class SessionIdManager {
|
|
|
826
827
|
_setSessionId(sessionId: string | null, sessionActivityTimestamp: number | null, sessionStartTimestamp: number | null): void;
|
|
827
828
|
_getSessionId(): [number, string, number];
|
|
828
829
|
resetSessionId(): void;
|
|
830
|
+
_listenToReloadWindow(): void;
|
|
829
831
|
checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): {
|
|
830
832
|
sessionId: string;
|
|
831
833
|
windowId: string;
|
package/dist/module.js
CHANGED
|
@@ -885,7 +885,7 @@ var LZString = {
|
|
|
885
885
|
}
|
|
886
886
|
};
|
|
887
887
|
|
|
888
|
-
var version = "1.
|
|
888
|
+
var version = "1.31.0";
|
|
889
889
|
|
|
890
890
|
// e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
|
|
891
891
|
|
|
@@ -5549,12 +5549,28 @@ var SessionIdManager = /*#__PURE__*/function () {
|
|
|
5549
5549
|
this._sessionId = undefined;
|
|
5550
5550
|
this._sessionStartTimestamp = null;
|
|
5551
5551
|
this._sessionActivityTimestamp = null;
|
|
5552
|
+
var persistenceName = config['persistence_name'] || config['token'];
|
|
5553
|
+
this.window_id_storage_key = 'ph_' + persistenceName + '_window_id';
|
|
5554
|
+
this.primary_window_exists_storage_key = 'ph_' + persistenceName + '_primary_window_exists'; // primary_window_exists is set when the DOM has been loaded and is cleared on unload
|
|
5555
|
+
// if it exists here it means there was no unload which suggests this window is opened as a tab duplication, window.open, etc.
|
|
5556
|
+
|
|
5557
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5558
|
+
var lastWindowId = sessionStore.parse(this.window_id_storage_key);
|
|
5559
|
+
var primaryWindowExists = sessionStore.parse(this.primary_window_exists_storage_key);
|
|
5560
|
+
|
|
5561
|
+
if (lastWindowId && !primaryWindowExists) {
|
|
5562
|
+
// Persist window from previous storage state
|
|
5563
|
+
this._windowId = lastWindowId;
|
|
5564
|
+
} else {
|
|
5565
|
+
// Wipe any reference to previous window id
|
|
5566
|
+
sessionStore.remove(this.window_id_storage_key);
|
|
5567
|
+
} // Flag this session as having a primary window
|
|
5552
5568
|
|
|
5553
|
-
|
|
5554
|
-
this.
|
|
5555
|
-
} else {
|
|
5556
|
-
this.window_id_storage_key = 'ph_' + config['token'] + '_window_id';
|
|
5569
|
+
|
|
5570
|
+
sessionStore.set(this.primary_window_exists_storage_key, true);
|
|
5557
5571
|
}
|
|
5572
|
+
|
|
5573
|
+
this._listenToReloadWindow();
|
|
5558
5574
|
} // Note: this tries to store the windowId in sessionStorage. SessionStorage is unique to the current window/tab,
|
|
5559
5575
|
// and persists page loads/reloads. So it's uniquely suited for storing the windowId. This function also respects
|
|
5560
5576
|
// when persistence is disabled (by user config) and when sessionStorage is not supported (it *should* be supported on all browsers),
|
|
@@ -5581,7 +5597,8 @@ var SessionIdManager = /*#__PURE__*/function () {
|
|
|
5581
5597
|
|
|
5582
5598
|
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5583
5599
|
return sessionStore.parse(this.window_id_storage_key);
|
|
5584
|
-
}
|
|
5600
|
+
} // New window id will be generated
|
|
5601
|
+
|
|
5585
5602
|
|
|
5586
5603
|
return null;
|
|
5587
5604
|
} // Note: 'this.persistence.register' can be disabled in the config.
|
|
@@ -5620,6 +5637,24 @@ var SessionIdManager = /*#__PURE__*/function () {
|
|
|
5620
5637
|
value: function resetSessionId() {
|
|
5621
5638
|
this._setSessionId(null, null, null);
|
|
5622
5639
|
}
|
|
5640
|
+
/*
|
|
5641
|
+
* Listens to window unloads and removes the primaryWindowExists key from sessionStorage.
|
|
5642
|
+
* Reloaded or fresh tabs created after a DOM unloads (reloading the same tab) WILL NOT have this primaryWindowExists flag in session storage.
|
|
5643
|
+
* Cloned sessions (new tab, tab duplication, window.open(), ...) WILL have this primaryWindowExists flag in their copied session storage.
|
|
5644
|
+
* We conditionally check the primaryWindowExists value in the constructor to decide if the window id in the last session storage should be carried over.
|
|
5645
|
+
*/
|
|
5646
|
+
|
|
5647
|
+
}, {
|
|
5648
|
+
key: "_listenToReloadWindow",
|
|
5649
|
+
value: function _listenToReloadWindow() {
|
|
5650
|
+
var _this = this;
|
|
5651
|
+
|
|
5652
|
+
window.addEventListener('beforeunload', function () {
|
|
5653
|
+
if (!_this.persistence.disabled && sessionStore.is_supported()) {
|
|
5654
|
+
sessionStore.remove(_this.primary_window_exists_storage_key);
|
|
5655
|
+
}
|
|
5656
|
+
});
|
|
5657
|
+
}
|
|
5623
5658
|
/*
|
|
5624
5659
|
* This function returns the current sessionId and windowId. It should be used to
|
|
5625
5660
|
* access these values over directly calling `._sessionId` or `._windowId`. In addition
|
|
@@ -5830,6 +5865,8 @@ var SentryIntegration = /*#__PURE__*/_createClass(function SentryIntegration(_po
|
|
|
5830
5865
|
|
|
5831
5866
|
this.setupOnce = function (addGlobalEventProcessor) {
|
|
5832
5867
|
addGlobalEventProcessor(function (event) {
|
|
5868
|
+
var _event$exception, _exceptions$, _exceptions$2;
|
|
5869
|
+
|
|
5833
5870
|
if (event.level !== 'error' || !_posthog.__loaded) return event;
|
|
5834
5871
|
if (!event.tags) event.tags = {};
|
|
5835
5872
|
event.tags['PostHog Person URL'] = _posthog.config.api_host + '/person/' + _posthog.get_distinct_id();
|
|
@@ -5838,9 +5875,13 @@ var SentryIntegration = /*#__PURE__*/_createClass(function SentryIntegration(_po
|
|
|
5838
5875
|
event.tags['PostHog Recording URL'] = _posthog.config.api_host + '/recordings/#sessionRecordingId=' + _posthog.sessionManager.checkAndGetSessionAndWindowId(true).sessionId;
|
|
5839
5876
|
}
|
|
5840
5877
|
|
|
5878
|
+
var exceptions = ((_event$exception = event.exception) === null || _event$exception === void 0 ? void 0 : _event$exception.values) || [];
|
|
5841
5879
|
var data = {
|
|
5842
5880
|
$sentry_event_id: event.event_id,
|
|
5843
|
-
$sentry_exception: event.exception
|
|
5881
|
+
$sentry_exception: event.exception,
|
|
5882
|
+
$sentry_exception_message: (_exceptions$ = exceptions[0]) === null || _exceptions$ === void 0 ? void 0 : _exceptions$.value,
|
|
5883
|
+
$sentry_exception_type: (_exceptions$2 = exceptions[0]) === null || _exceptions$2 === void 0 ? void 0 : _exceptions$2.type,
|
|
5884
|
+
$sentry_tags: event.tags
|
|
5844
5885
|
};
|
|
5845
5886
|
if (organization && projectId) data['$sentry_url'] = (prefix || 'https://sentry.io/organizations/') + organization + '/issues/?project=' + projectId + '&query=' + event.event_id;
|
|
5846
5887
|
|