posthog-js 1.286.0 → 1.287.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.
@@ -0,0 +1,9 @@
1
+ import { PostHog } from '../../../posthog-core';
2
+ export declare class FlushedSizeTracker {
3
+ private readonly _getProperty;
4
+ private readonly _setProperty;
5
+ constructor(posthog: PostHog);
6
+ trackSize(size: number): void;
7
+ reset(): void;
8
+ get currentTrackedSize(): number;
9
+ }
@@ -79,6 +79,7 @@ export declare class LazyLoadedSessionRecording implements LazyLoadedSessionReco
79
79
  private _buffer;
80
80
  private _removePageViewCaptureHook;
81
81
  private _removeEventTriggerCaptureHook;
82
+ private _flushedSizeTracker;
82
83
  private get _sessionManager();
83
84
  private get _sessionIdleThresholdMilliseconds();
84
85
  private get _isSampled();
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.286.0",
3
+ "version": "1.287.0",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",
@@ -0,0 +1,9 @@
1
+ import { PostHog } from '../../../posthog-core';
2
+ export declare class FlushedSizeTracker {
3
+ private readonly _getProperty;
4
+ private readonly _setProperty;
5
+ constructor(posthog: PostHog);
6
+ trackSize(size: number): void;
7
+ reset(): void;
8
+ get currentTrackedSize(): number;
9
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlushedSizeTracker = void 0;
4
+ var SESSION_RECORDING_FLUSHED_SIZE = '$sess_rec_flush_size';
5
+ var FlushedSizeTracker = /** @class */ (function () {
6
+ function FlushedSizeTracker(posthog) {
7
+ if (!posthog.persistence) {
8
+ throw new Error('it is not valid to not have persistence and be this far into setting up the application');
9
+ }
10
+ this._getProperty = posthog.get_property.bind(posthog);
11
+ this._setProperty = posthog.persistence.set_property.bind(posthog.persistence);
12
+ }
13
+ FlushedSizeTracker.prototype.trackSize = function (size) {
14
+ var currentFlushed = Number(this._getProperty(SESSION_RECORDING_FLUSHED_SIZE)) || 0;
15
+ var newValue = currentFlushed + size;
16
+ this._setProperty(SESSION_RECORDING_FLUSHED_SIZE, newValue);
17
+ };
18
+ FlushedSizeTracker.prototype.reset = function () {
19
+ return this._setProperty(SESSION_RECORDING_FLUSHED_SIZE, 0);
20
+ };
21
+ Object.defineProperty(FlushedSizeTracker.prototype, "currentTrackedSize", {
22
+ get: function () {
23
+ return Number(this._getProperty(SESSION_RECORDING_FLUSHED_SIZE)) || 0;
24
+ },
25
+ enumerable: false,
26
+ configurable: true
27
+ });
28
+ return FlushedSizeTracker;
29
+ }());
30
+ exports.FlushedSizeTracker = FlushedSizeTracker;
31
+ //# sourceMappingURL=flushed-size-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flushed-size-tracker.js","sourceRoot":"","sources":["../../../../../src/extensions/replay/external/flushed-size-tracker.ts"],"names":[],"mappings":";;;AAGA,IAAM,8BAA8B,GAAG,sBAAsB,CAAA;AAE7D;IAII,4BAAY,OAAgB;QACxB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAA;QAC9G,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACtD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAClF,CAAC;IAED,sCAAS,GAAT,UAAU,IAAY;QAClB,IAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,8BAA8B,CAAC,CAAC,IAAI,CAAC,CAAA;QACrF,IAAM,QAAQ,GAAG,cAAc,GAAG,IAAI,CAAA;QACtC,IAAI,CAAC,YAAY,CAAC,8BAA8B,EAAE,QAAQ,CAAC,CAAA;IAC/D,CAAC;IAED,kCAAK,GAAL;QACI,OAAO,IAAI,CAAC,YAAY,CAAC,8BAA8B,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED,sBAAI,kDAAkB;aAAtB;YACI,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,8BAA8B,CAAC,CAAC,IAAI,CAAC,CAAA;QACzE,CAAC;;;OAAA;IACL,yBAAC;AAAD,CAAC,AA1BD,IA0BC;AA1BY,gDAAkB","sourcesContent":["import { PostHog } from '../../../posthog-core'\nimport { Property } from '../../../types'\n\nconst SESSION_RECORDING_FLUSHED_SIZE = '$sess_rec_flush_size'\n\nexport class FlushedSizeTracker {\n private readonly _getProperty: (property_name: string) => Property | undefined\n private readonly _setProperty: (prop: string, to: any) => void\n\n constructor(posthog: PostHog) {\n if (!posthog.persistence) {\n throw new Error('it is not valid to not have persistence and be this far into setting up the application')\n }\n\n this._getProperty = posthog.get_property.bind(posthog)\n this._setProperty = posthog.persistence.set_property.bind(posthog.persistence)\n }\n\n trackSize(size: number) {\n const currentFlushed = Number(this._getProperty(SESSION_RECORDING_FLUSHED_SIZE)) || 0\n const newValue = currentFlushed + size\n this._setProperty(SESSION_RECORDING_FLUSHED_SIZE, newValue)\n }\n\n reset() {\n return this._setProperty(SESSION_RECORDING_FLUSHED_SIZE, 0)\n }\n\n get currentTrackedSize(): number {\n return Number(this._getProperty(SESSION_RECORDING_FLUSHED_SIZE)) || 0\n }\n}\n"]}
@@ -79,6 +79,7 @@ export declare class LazyLoadedSessionRecording implements LazyLoadedSessionReco
79
79
  private _buffer;
80
80
  private _removePageViewCaptureHook;
81
81
  private _removeEventTriggerCaptureHook;
82
+ private _flushedSizeTracker;
82
83
  private get _sessionManager();
83
84
  private get _sessionIdleThresholdMilliseconds();
84
85
  private get _isSampled();
@@ -66,6 +66,7 @@ var constants_1 = require("../../../constants");
66
66
  var request_utils_1 = require("../../../utils/request-utils");
67
67
  var config_2 = __importDefault(require("../../../config"));
68
68
  var sampling_1 = require("../../sampling");
69
+ var flushed_size_tracker_1 = require("./flushed-size-tracker");
69
70
  var BASE_ENDPOINT = '/s/';
70
71
  var DEFAULT_CANVAS_QUALITY = 0.4;
71
72
  var DEFAULT_CANVAS_FPS = 4;
@@ -202,6 +203,7 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
202
203
  this._samplingSessionListener = undefined;
203
204
  this._forceIdleSessionIdListener = undefined;
204
205
  this._onSessionIdCallback = function (sessionId, windowId, changeReason) {
206
+ var _a;
205
207
  if (!changeReason)
206
208
  return;
207
209
  var wasLikelyReset = changeReason.noSessionId;
@@ -217,8 +219,13 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
217
219
  // we'll need to correct the time of this if it's captured when idle
218
220
  // so we don't extend reported session time with a debug event
219
221
  lastActivityTimestamp: _this._lastActivityTimestamp,
222
+ flushed_size: (_a = _this._flushedSizeTracker) === null || _a === void 0 ? void 0 : _a.currentTrackedSize,
220
223
  });
221
224
  }
225
+ // reset flushed size tracker after capturing the ending event
226
+ if (_this._flushedSizeTracker) {
227
+ _this._flushedSizeTracker.reset();
228
+ }
222
229
  _this._tryAddCustomEvent('$session_id_change', { sessionId: sessionId, windowId: windowId, changeReason: changeReason });
223
230
  _this._clearConditionalRecordingPersistence();
224
231
  if (!_this._stopRrweb) {
@@ -264,6 +271,7 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
264
271
  if (this._sessionIdleThresholdMilliseconds >= this._sessionManager.sessionTimeoutMs) {
265
272
  logger.warn("session_idle_threshold_ms (".concat(this._sessionIdleThresholdMilliseconds, ") is greater than the session timeout (").concat(this._sessionManager.sessionTimeoutMs, "). Session will never be detected as idle"));
266
273
  }
274
+ this._flushedSizeTracker = new flushed_size_tracker_1.FlushedSizeTracker(this._instance);
267
275
  }
268
276
  Object.defineProperty(LazyLoadedSessionRecording.prototype, "sessionId", {
269
277
  get: function () {
@@ -897,6 +905,8 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
897
905
  if (this._buffer.data.length > 0) {
898
906
  var snapshotEvents = splitBuffer(this._buffer);
899
907
  snapshotEvents.forEach(function (snapshotBuffer) {
908
+ var _a;
909
+ (_a = _this._flushedSizeTracker) === null || _a === void 0 ? void 0 : _a.trackSize(snapshotBuffer.size);
900
910
  _this._captureSnapshot({
901
911
  $snapshot_bytes: snapshotBuffer.size,
902
912
  $snapshot_data: snapshotBuffer.data,
@@ -1115,6 +1125,7 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
1115
1125
  };
1116
1126
  Object.defineProperty(LazyLoadedSessionRecording.prototype, "sdkDebugProperties", {
1117
1127
  get: function () {
1128
+ var _a;
1118
1129
  var sessionStartTimestamp = this._sessionManager.checkAndGetSessionAndWindowId(true).sessionStartTimestamp;
1119
1130
  return {
1120
1131
  $recording_status: this.status,
@@ -1122,6 +1133,7 @@ var LazyLoadedSessionRecording = /** @class */ (function () {
1122
1133
  $sdk_debug_replay_internal_buffer_size: this._buffer.size,
1123
1134
  $sdk_debug_current_session_duration: this._sessionDuration,
1124
1135
  $sdk_debug_session_start: sessionStartTimestamp,
1136
+ $sdk_debug_replay_flushed_size: (_a = this._flushedSizeTracker) === null || _a === void 0 ? void 0 : _a.currentTrackedSize,
1125
1137
  };
1126
1138
  },
1127
1139
  enumerable: false,