posthog-js 1.46.2 → 1.47.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/dist/module.d.ts CHANGED
@@ -856,6 +856,7 @@ declare class SessionRecording {
856
856
  stopRecording(): void;
857
857
  isRecordingEnabled(): boolean;
858
858
  isConsoleLogCaptureEnabled(): boolean;
859
+ getRecordingVersion(): any;
859
860
  afterDecideResponse(response: DecideResponse): void;
860
861
  startCaptureAndTrySendingQueuedSnapshots(): void;
861
862
  _startCapture(): void;
@@ -974,7 +975,7 @@ declare class PageViewIdManager {
974
975
  */
975
976
  declare class PostHog {
976
977
  __loaded: boolean;
977
- __loaded_recorder: boolean;
978
+ __loaded_recorder_version: 'v1' | 'v2' | undefined;
978
979
  config: PostHogConfig;
979
980
  persistence: PostHogPersistence;
980
981
  sessionManager: SessionIdManager;
package/dist/module.js CHANGED
@@ -921,7 +921,7 @@ var LZString = {
921
921
  }
922
922
  };
923
923
 
924
- var version = "1.46.2";
924
+ var version = "1.47.0";
925
925
 
926
926
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
927
927
 
@@ -3538,6 +3538,8 @@ var CAMPAIGN_IDS_KEY = '__cmpns';
3538
3538
  var EVENT_TIMERS_KEY = '__timers';
3539
3539
  var SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side';
3540
3540
  var CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side';
3541
+ var SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE = '$session_recording_recorder_version_server_side'; // follows rrweb versioning
3542
+
3541
3543
  var SESSION_ID = '$sesid';
3542
3544
  var ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
3543
3545
  var USER_STATE = '$user_state';
@@ -3991,26 +3993,35 @@ var SessionRecording = /*#__PURE__*/function () {
3991
3993
  var enabled_client_side = this.instance.get_config('enable_recording_console_log');
3992
3994
  return enabled_client_side !== null && enabled_client_side !== void 0 ? enabled_client_side : enabled_server_side;
3993
3995
  }
3996
+ }, {
3997
+ key: "getRecordingVersion",
3998
+ value: function getRecordingVersion() {
3999
+ var _this$instance$get_co;
4000
+
4001
+ var recordingVersion_server_side = this.instance.get_property(SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE);
4002
+ var recordingVersion_client_side = (_this$instance$get_co = this.instance.get_config('session_recording')) === null || _this$instance$get_co === void 0 ? void 0 : _this$instance$get_co.recorderVersion;
4003
+ return recordingVersion_client_side || recordingVersion_server_side || 'v1';
4004
+ }
3994
4005
  }, {
3995
4006
  key: "afterDecideResponse",
3996
4007
  value: function afterDecideResponse(response) {
3997
- var _response$sessionReco2, _response$sessionReco4;
4008
+ var _response$sessionReco3, _response$sessionReco5;
3998
4009
 
3999
4010
  this.receivedDecide = true;
4000
4011
 
4001
4012
  if (this.instance.persistence) {
4002
- var _response$sessionReco, _this$instance$persis;
4013
+ var _response$sessionReco, _response$sessionReco2, _this$instance$persis;
4003
4014
 
4004
- this.instance.persistence.register((_this$instance$persis = {}, _defineProperty(_this$instance$persis, SESSION_RECORDING_ENABLED_SERVER_SIDE, !!response['sessionRecording']), _defineProperty(_this$instance$persis, CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE, (_response$sessionReco = response.sessionRecording) === null || _response$sessionReco === void 0 ? void 0 : _response$sessionReco.consoleLogRecordingEnabled), _this$instance$persis));
4015
+ this.instance.persistence.register((_this$instance$persis = {}, _defineProperty(_this$instance$persis, SESSION_RECORDING_ENABLED_SERVER_SIDE, !!response['sessionRecording']), _defineProperty(_this$instance$persis, CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE, (_response$sessionReco = response.sessionRecording) === null || _response$sessionReco === void 0 ? void 0 : _response$sessionReco.consoleLogRecordingEnabled), _defineProperty(_this$instance$persis, SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE, (_response$sessionReco2 = response.sessionRecording) === null || _response$sessionReco2 === void 0 ? void 0 : _response$sessionReco2.recorderVersion), _this$instance$persis));
4005
4016
  }
4006
4017
 
4007
- if ((_response$sessionReco2 = response.sessionRecording) !== null && _response$sessionReco2 !== void 0 && _response$sessionReco2.endpoint) {
4008
- var _response$sessionReco3;
4018
+ if ((_response$sessionReco3 = response.sessionRecording) !== null && _response$sessionReco3 !== void 0 && _response$sessionReco3.endpoint) {
4019
+ var _response$sessionReco4;
4009
4020
 
4010
- this.endpoint = (_response$sessionReco3 = response.sessionRecording) === null || _response$sessionReco3 === void 0 ? void 0 : _response$sessionReco3.endpoint;
4021
+ this.endpoint = (_response$sessionReco4 = response.sessionRecording) === null || _response$sessionReco4 === void 0 ? void 0 : _response$sessionReco4.endpoint;
4011
4022
  }
4012
4023
 
4013
- if ((_response$sessionReco4 = response.sessionRecording) !== null && _response$sessionReco4 !== void 0 && _response$sessionReco4.recorderVersion) {
4024
+ if ((_response$sessionReco5 = response.sessionRecording) !== null && _response$sessionReco5 !== void 0 && _response$sessionReco5.recorderVersion) {
4014
4025
  this.recorderVersion = response.sessionRecording.recorderVersion;
4015
4026
  }
4016
4027
 
@@ -4044,17 +4055,16 @@ var SessionRecording = /*#__PURE__*/function () {
4044
4055
  // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.
4045
4056
  if (typeof Object.assign === 'undefined') {
4046
4057
  return;
4047
- }
4058
+ } // Nested if block ensures we do not switch recorder versions midway through a recording.
4048
4059
 
4049
- if (!this.captureStarted && !this.instance.get_config('disable_session_recording')) {
4050
- var userSessionRecordingOptions = this.instance.get_config('session_recording'); // Always use the client side setting if given, otherwise use the server side setting
4051
4060
 
4052
- this.recorderVersion = (userSessionRecordingOptions === null || userSessionRecordingOptions === void 0 ? void 0 : userSessionRecordingOptions.recorderVersion) || this.recorderVersion;
4053
- var recorderJS = this.recorderVersion === 'v2' ? 'recorder-v2.js' : 'recorder.js';
4054
- this.captureStarted = true; // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is imported), don't load script.
4055
- // Otherwise, remotely import recorder.js from cdn since it hasn't been loaded
4061
+ if (!this.captureStarted && !this.instance.get_config('disable_session_recording')) {
4062
+ var recorderJS = this.getRecordingVersion() === 'v2' ? 'recorder-v2.js' : 'recorder.js';
4063
+ this.captureStarted = true; // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is
4064
+ // imported) or matches the requested recorder version, don't load script. Otherwise, remotely import
4065
+ // recorder.js from cdn since it hasn't been loaded.
4056
4066
 
4057
- if (!this.instance.__loaded_recorder) {
4067
+ if (this.instance.__loaded_recorder_version !== this.getRecordingVersion()) {
4058
4068
  loadScript(this.instance.get_config('api_host') + "/static/".concat(recorderJS, "?v=").concat(Config.LIB_VERSION), this._onScriptLoaded.bind(this));
4059
4069
  }
4060
4070
 
@@ -6576,7 +6586,7 @@ var create_mplib = function create_mplib(token, config, name) {
6576
6586
 
6577
6587
 
6578
6588
  var PostHog = /*#__PURE__*/function () {
6579
- // flag that checks if recorder.js is loaded already
6589
+ // flag that keeps track of which version of recorder is loaded
6580
6590
  function PostHog() {
6581
6591
  var _this = this;
6582
6592
 
@@ -6594,7 +6604,7 @@ var PostHog = /*#__PURE__*/function () {
6594
6604
  this.__captureHooks = [];
6595
6605
  this.__request_queue = [];
6596
6606
  this.__loaded = false;
6597
- this.__loaded_recorder = false;
6607
+ this.__loaded_recorder_version = undefined;
6598
6608
  this.__autocapture = undefined;
6599
6609
 
6600
6610
  this._jsc = function () {};
@@ -6680,7 +6690,11 @@ var PostHog = /*#__PURE__*/function () {
6680
6690
 
6681
6691
 
6682
6692
  if (win !== null && win !== void 0 && (_window$rrweb = win.rrweb) !== null && _window$rrweb !== void 0 && _window$rrweb.record || win !== null && win !== void 0 && win.rrwebRecord) {
6683
- this.__loaded_recorder = true;
6693
+ var _window$rrweb2;
6694
+
6695
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6696
+ // @ts-ignore
6697
+ this.__loaded_recorder_version = win === null || win === void 0 ? void 0 : (_window$rrweb2 = win.rrweb) === null || _window$rrweb2 === void 0 ? void 0 : _window$rrweb2.version;
6684
6698
  }
6685
6699
 
6686
6700
  this._captureMetrics = new CaptureMetrics(this.get_config('_capture_metrics'));