posthog-js 1.15.3 → 1.16.2
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 +16 -0
- package/dist/array.js +11 -11
- package/dist/es.js +248 -62
- package/dist/module.d.ts +11 -0
- package/dist/module.js +248 -62
- package/package.json +2 -2
package/dist/module.js
CHANGED
|
@@ -865,9 +865,9 @@ var LZString = {
|
|
|
865
865
|
}
|
|
866
866
|
};
|
|
867
867
|
|
|
868
|
-
var version = "1.
|
|
868
|
+
var version = "1.16.2";
|
|
869
869
|
|
|
870
|
-
var Config = {
|
|
870
|
+
var Config$1 = {
|
|
871
871
|
DEBUG: false,
|
|
872
872
|
LIB_VERSION: version
|
|
873
873
|
};
|
|
@@ -905,7 +905,7 @@ var _ = {
|
|
|
905
905
|
var console$1 = {
|
|
906
906
|
/** @type {function(...*)} */
|
|
907
907
|
log: function log() {
|
|
908
|
-
if (Config.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
908
|
+
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
909
909
|
try {
|
|
910
910
|
window.console.log.apply(window.console, arguments);
|
|
911
911
|
} catch (err) {
|
|
@@ -918,7 +918,7 @@ var console$1 = {
|
|
|
918
918
|
|
|
919
919
|
/** @type {function(...*)} */
|
|
920
920
|
error: function error() {
|
|
921
|
-
if (Config.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
921
|
+
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
922
922
|
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments));
|
|
923
923
|
|
|
924
924
|
try {
|
|
@@ -1142,7 +1142,7 @@ _.safewrap = function (f) {
|
|
|
1142
1142
|
} catch (e) {
|
|
1143
1143
|
console$1.critical('Implementation error. Please turn on debug and contact support@posthog.com.');
|
|
1144
1144
|
|
|
1145
|
-
if (Config.DEBUG) {
|
|
1145
|
+
if (Config$1.DEBUG) {
|
|
1146
1146
|
console$1.critical(e);
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
@@ -1736,7 +1736,7 @@ _.info = {
|
|
|
1736
1736
|
$viewport_height: window.innerHeight,
|
|
1737
1737
|
$viewport_width: window.innerWidth,
|
|
1738
1738
|
$lib: 'web',
|
|
1739
|
-
$lib_version: Config.LIB_VERSION,
|
|
1739
|
+
$lib_version: Config$1.LIB_VERSION,
|
|
1740
1740
|
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
|
|
1741
1741
|
$time: _.timestamp() / 1000 // epoch time in seconds
|
|
1742
1742
|
|
|
@@ -2539,6 +2539,73 @@ var memoryStore = {
|
|
|
2539
2539
|
remove: function remove(name) {
|
|
2540
2540
|
delete memoryStorage[name];
|
|
2541
2541
|
}
|
|
2542
|
+
}; // Storage that only lasts the length of a tab/window. Survives page refreshes
|
|
2543
|
+
|
|
2544
|
+
var sessionStore = {
|
|
2545
|
+
sessionStorageSupported: null,
|
|
2546
|
+
is_supported: function is_supported() {
|
|
2547
|
+
if (sessionStore.sessionStorageSupported !== null) {
|
|
2548
|
+
return sessionStore.sessionStorageSupported;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
sessionStore.sessionStorageSupported = true;
|
|
2552
|
+
|
|
2553
|
+
if (window) {
|
|
2554
|
+
try {
|
|
2555
|
+
var key = '__support__',
|
|
2556
|
+
val = 'xyz';
|
|
2557
|
+
sessionStore.set(key, val);
|
|
2558
|
+
|
|
2559
|
+
if (sessionStore.get(key) !== '"xyz"') {
|
|
2560
|
+
sessionStore.sessionStorageSupported = false;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
sessionStore.remove(key);
|
|
2564
|
+
} catch (err) {
|
|
2565
|
+
sessionStore.sessionStorageSupported = false;
|
|
2566
|
+
}
|
|
2567
|
+
} else {
|
|
2568
|
+
sessionStore.sessionStorageSupported = false;
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
return sessionStore.sessionStorageSupported;
|
|
2572
|
+
},
|
|
2573
|
+
error: function error(msg) {
|
|
2574
|
+
if (Config.DEBUG) {
|
|
2575
|
+
console$1.error('sessionStorage error: ', msg);
|
|
2576
|
+
}
|
|
2577
|
+
},
|
|
2578
|
+
get: function get(name) {
|
|
2579
|
+
try {
|
|
2580
|
+
return window.sessionStorage.getItem(name);
|
|
2581
|
+
} catch (err) {
|
|
2582
|
+
sessionStore.error(err);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
return null;
|
|
2586
|
+
},
|
|
2587
|
+
parse: function parse(name) {
|
|
2588
|
+
try {
|
|
2589
|
+
return JSON.parse(sessionStore.get(name)) || null;
|
|
2590
|
+
} catch (err) {// noop
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
return null;
|
|
2594
|
+
},
|
|
2595
|
+
set: function set(name, value) {
|
|
2596
|
+
try {
|
|
2597
|
+
window.sessionStorage.setItem(name, JSON.stringify(value));
|
|
2598
|
+
} catch (err) {
|
|
2599
|
+
sessionStore.error(err);
|
|
2600
|
+
}
|
|
2601
|
+
},
|
|
2602
|
+
remove: function remove(name) {
|
|
2603
|
+
try {
|
|
2604
|
+
window.sessionStorage.removeItem(name);
|
|
2605
|
+
} catch (err) {
|
|
2606
|
+
sessionStore.error(err);
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2542
2609
|
};
|
|
2543
2610
|
|
|
2544
2611
|
/**
|
|
@@ -3514,28 +3581,6 @@ PostHogPersistence.prototype.remove_event_timer = function (event_name) {
|
|
|
3514
3581
|
return timestamp;
|
|
3515
3582
|
};
|
|
3516
3583
|
|
|
3517
|
-
var SESSION_CHANGE_THRESHOLD = 30 * 60 * 1000; // 30 mins
|
|
3518
|
-
|
|
3519
|
-
var sessionIdGenerator = (function (persistence, timestamp) {
|
|
3520
|
-
var _ref = persistence['props'][SESSION_ID] || [0, null],
|
|
3521
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
3522
|
-
lastTimestamp = _ref2[0],
|
|
3523
|
-
sessionId = _ref2[1];
|
|
3524
|
-
|
|
3525
|
-
var isNewSessionId = false;
|
|
3526
|
-
|
|
3527
|
-
if (Math.abs(timestamp - lastTimestamp) > SESSION_CHANGE_THRESHOLD) {
|
|
3528
|
-
sessionId = _.UUID();
|
|
3529
|
-
isNewSessionId = true;
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
persistence.register(_defineProperty({}, SESSION_ID, [timestamp, sessionId]));
|
|
3533
|
-
return {
|
|
3534
|
-
isNewSessionId: isNewSessionId,
|
|
3535
|
-
sessionId: sessionId
|
|
3536
|
-
};
|
|
3537
|
-
});
|
|
3538
|
-
|
|
3539
3584
|
var replacementImageURI = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg==';
|
|
3540
3585
|
/*
|
|
3541
3586
|
* Check whether a data payload is nearing 5mb. If it is, it checks the data for
|
|
@@ -3587,6 +3632,10 @@ function filterDataURLsFromLargeDataObjects(data) {
|
|
|
3587
3632
|
}
|
|
3588
3633
|
|
|
3589
3634
|
var BASE_ENDPOINT = '/e/';
|
|
3635
|
+
var FULL_SNAPSHOT_EVENT_TYPE = 2;
|
|
3636
|
+
var META_EVENT_TYPE = 4;
|
|
3637
|
+
var INCREMENTAL_SNAPSHOT_EVENT_TYPE = 3;
|
|
3638
|
+
var MUTATION_SOURCE_TYPE = 3;
|
|
3590
3639
|
var SessionRecording = /*#__PURE__*/function () {
|
|
3591
3640
|
function SessionRecording(instance) {
|
|
3592
3641
|
_classCallCheck(this, SessionRecording);
|
|
@@ -3597,6 +3646,8 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3597
3646
|
this.emit = false;
|
|
3598
3647
|
this.endpoint = BASE_ENDPOINT;
|
|
3599
3648
|
this.stopRrweb = null;
|
|
3649
|
+
this.windowId = null;
|
|
3650
|
+
this.sessionId = null;
|
|
3600
3651
|
}
|
|
3601
3652
|
|
|
3602
3653
|
_createClass(SessionRecording, [{
|
|
@@ -3666,9 +3717,24 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3666
3717
|
|
|
3667
3718
|
if (!this.captureStarted && !this.instance.get_config('disable_session_recording')) {
|
|
3668
3719
|
this.captureStarted = true;
|
|
3669
|
-
loadScript(this.instance.get_config('api_host') + '/static/recorder.js?v=' + Config.LIB_VERSION, _.bind(this._onScriptLoaded, this));
|
|
3720
|
+
loadScript(this.instance.get_config('api_host') + '/static/recorder.js?v=' + Config$1.LIB_VERSION, _.bind(this._onScriptLoaded, this));
|
|
3670
3721
|
}
|
|
3671
3722
|
}
|
|
3723
|
+
}, {
|
|
3724
|
+
key: "_updateWindowAndSessionIds",
|
|
3725
|
+
value: function _updateWindowAndSessionIds(event) {
|
|
3726
|
+
var _this$instance$_sessi = this.instance._sessionIdManager.getSessionAndWindowId(event.timestamp || new Date().getTime(), event),
|
|
3727
|
+
windowId = _this$instance$_sessi.windowId,
|
|
3728
|
+
sessionId = _this$instance$_sessi.sessionId; // Event types FullSnapshot and Meta mean we're already in the process of sending a full snapshot
|
|
3729
|
+
|
|
3730
|
+
|
|
3731
|
+
if ((this.windowId !== windowId || this.sessionId !== sessionId) && [FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1) {
|
|
3732
|
+
window.rrweb.record.takeFullSnapshot();
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
this.windowId = windowId;
|
|
3736
|
+
this.sessionId = sessionId;
|
|
3737
|
+
}
|
|
3672
3738
|
}, {
|
|
3673
3739
|
key: "_onScriptLoaded",
|
|
3674
3740
|
value: function _onScriptLoaded() {
|
|
@@ -3701,23 +3767,20 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3701
3767
|
}
|
|
3702
3768
|
|
|
3703
3769
|
this.stopRrweb = window.rrweb.record(_objectSpread2({
|
|
3704
|
-
emit: function emit(
|
|
3705
|
-
|
|
3706
|
-
var sessionIdObject = sessionIdGenerator(_this2.instance.persistence, data.timestamp); // Data type 2 and 4 are FullSnapshot and Meta and they mean we're already
|
|
3707
|
-
// in the process of sending a full snapshot
|
|
3770
|
+
emit: function emit(event) {
|
|
3771
|
+
event = filterDataURLsFromLargeDataObjects(event);
|
|
3708
3772
|
|
|
3709
|
-
|
|
3710
|
-
window.rrweb.record.takeFullSnapshot();
|
|
3711
|
-
}
|
|
3773
|
+
_this2._updateWindowAndSessionIds(event);
|
|
3712
3774
|
|
|
3713
3775
|
var properties = {
|
|
3714
|
-
$snapshot_data:
|
|
3715
|
-
$session_id:
|
|
3776
|
+
$snapshot_data: event,
|
|
3777
|
+
$session_id: _this2.sessionId,
|
|
3778
|
+
$window_id: _this2.windowId
|
|
3716
3779
|
};
|
|
3717
3780
|
|
|
3718
3781
|
_this2.instance._captureMetrics.incr('rrweb-record');
|
|
3719
3782
|
|
|
3720
|
-
_this2.instance._captureMetrics.incr("rrweb-record-".concat(
|
|
3783
|
+
_this2.instance._captureMetrics.incr("rrweb-record-".concat(event.type));
|
|
3721
3784
|
|
|
3722
3785
|
if (_this2.emit) {
|
|
3723
3786
|
_this2._captureSnapshot(properties);
|
|
@@ -3748,7 +3811,7 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3748
3811
|
_noTruncate: true,
|
|
3749
3812
|
_batchKey: 'sessionRecording',
|
|
3750
3813
|
_metrics: {
|
|
3751
|
-
rrweb_full_snapshot: properties.$snapshot_data.type ===
|
|
3814
|
+
rrweb_full_snapshot: properties.$snapshot_data.type === FULL_SNAPSHOT_EVENT_TYPE
|
|
3752
3815
|
}
|
|
3753
3816
|
});
|
|
3754
3817
|
}
|
|
@@ -3938,7 +4001,7 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
3938
4001
|
var toolbarScript = 'toolbar.js';
|
|
3939
4002
|
var editorUrl = host + (host.endsWith('/') ? '' : '/') + 'static/' + toolbarScript + '?_ts=' + new Date().getTime();
|
|
3940
4003
|
loadScript(editorUrl, function () {
|
|
3941
|
-
window['ph_load_editor'](editorParams);
|
|
4004
|
+
window['ph_load_editor'](editorParams, _this.instance);
|
|
3942
4005
|
}); // Turbolinks doesn't fire an onload event but does replace the entire page, including the toolbar
|
|
3943
4006
|
|
|
3944
4007
|
_.register_event(window, 'turbolinks:load', function () {
|
|
@@ -5318,6 +5381,112 @@ var RetryQueue = /*#__PURE__*/function (_RequestQueueScaffold) {
|
|
|
5318
5381
|
return RetryQueue;
|
|
5319
5382
|
}(RequestQueueScaffold);
|
|
5320
5383
|
|
|
5384
|
+
var SESSION_CHANGE_THRESHOLD = 30 * 60 * 1000; // 30 mins
|
|
5385
|
+
|
|
5386
|
+
var SessionIdManager = /*#__PURE__*/function () {
|
|
5387
|
+
function SessionIdManager(config, persistence) {
|
|
5388
|
+
_classCallCheck(this, SessionIdManager);
|
|
5389
|
+
|
|
5390
|
+
this.persistence = persistence;
|
|
5391
|
+
|
|
5392
|
+
if (config['persistence_name']) {
|
|
5393
|
+
this.window_id_storage_key = 'ph_' + config['persistence_name'] + '_window_id';
|
|
5394
|
+
} else {
|
|
5395
|
+
this.window_id_storage_key = 'ph_' + config['token'] + '_window_id';
|
|
5396
|
+
}
|
|
5397
|
+
} // Note: this tries to store the windowId in sessionStorage. SessionStorage is unique to the current window/tab,
|
|
5398
|
+
// and persists page loads/reloads. So it's uniquely suited for storing the windowId. This function also respects
|
|
5399
|
+
// when persistence is disabled (by user config) and when sessionStorage is not supported (it *should* be supported on all browsers),
|
|
5400
|
+
// and in that case, it falls back to memory (which sadly, won't persist page loads)
|
|
5401
|
+
|
|
5402
|
+
|
|
5403
|
+
_createClass(SessionIdManager, [{
|
|
5404
|
+
key: "_setWindowId",
|
|
5405
|
+
value: function _setWindowId(windowId) {
|
|
5406
|
+
if (windowId !== this.windowId) {
|
|
5407
|
+
this.windowId = windowId;
|
|
5408
|
+
|
|
5409
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5410
|
+
sessionStore.set(this.window_id_storage_key, windowId);
|
|
5411
|
+
}
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
}, {
|
|
5415
|
+
key: "_getWindowId",
|
|
5416
|
+
value: function _getWindowId() {
|
|
5417
|
+
if (this.windowId) {
|
|
5418
|
+
return this.windowId;
|
|
5419
|
+
}
|
|
5420
|
+
|
|
5421
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5422
|
+
return sessionStore.parse(this.window_id_storage_key);
|
|
5423
|
+
}
|
|
5424
|
+
|
|
5425
|
+
return null;
|
|
5426
|
+
} // Note: 'this.persistence.register' can be disabled in the config.
|
|
5427
|
+
// In that case, this works by storing sessionId and the timestamp in memory.
|
|
5428
|
+
|
|
5429
|
+
}, {
|
|
5430
|
+
key: "_setSessionId",
|
|
5431
|
+
value: function _setSessionId(sessionId, timestamp) {
|
|
5432
|
+
if (sessionId !== this.sessionId || timestamp !== this.timestamp) {
|
|
5433
|
+
this.timestamp = timestamp;
|
|
5434
|
+
this.sessionId = sessionId;
|
|
5435
|
+
this.persistence.register(_defineProperty({}, SESSION_ID, [timestamp, sessionId]));
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
}, {
|
|
5439
|
+
key: "_getSessionId",
|
|
5440
|
+
value: function _getSessionId() {
|
|
5441
|
+
if (this.sessionId && this.timestamp) {
|
|
5442
|
+
return [this.timestamp, this.sessionId];
|
|
5443
|
+
}
|
|
5444
|
+
|
|
5445
|
+
return this.persistence['props'][SESSION_ID] || [0, null];
|
|
5446
|
+
}
|
|
5447
|
+
}, {
|
|
5448
|
+
key: "getSessionAndWindowId",
|
|
5449
|
+
value: function getSessionAndWindowId() {
|
|
5450
|
+
var _recordingEvent$data;
|
|
5451
|
+
|
|
5452
|
+
var timestamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
5453
|
+
var recordingEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
5454
|
+
// Some recording events are triggered by non-user events (e.g. "X minutes ago" text updating on the screen).
|
|
5455
|
+
// We don't want to update the session and window ids in these cases. These events are designated by event
|
|
5456
|
+
// type -> incremental update, and source -> mutation.
|
|
5457
|
+
var isUserInteraction = !(recordingEvent && recordingEvent.type === INCREMENTAL_SNAPSHOT_EVENT_TYPE && ((_recordingEvent$data = recordingEvent.data) === null || _recordingEvent$data === void 0 ? void 0 : _recordingEvent$data.source) === MUTATION_SOURCE_TYPE);
|
|
5458
|
+
timestamp = timestamp || new Date().getTime();
|
|
5459
|
+
|
|
5460
|
+
var _this$_getSessionId = this._getSessionId(),
|
|
5461
|
+
_this$_getSessionId2 = _slicedToArray(_this$_getSessionId, 2),
|
|
5462
|
+
lastTimestamp = _this$_getSessionId2[0],
|
|
5463
|
+
sessionId = _this$_getSessionId2[1];
|
|
5464
|
+
|
|
5465
|
+
var windowId = this._getWindowId();
|
|
5466
|
+
|
|
5467
|
+
if (!sessionId || isUserInteraction && Math.abs(timestamp - lastTimestamp) > SESSION_CHANGE_THRESHOLD) {
|
|
5468
|
+
sessionId = _.UUID();
|
|
5469
|
+
windowId = _.UUID();
|
|
5470
|
+
} else if (!windowId) {
|
|
5471
|
+
windowId = _.UUID();
|
|
5472
|
+
}
|
|
5473
|
+
|
|
5474
|
+
var newTimestamp = lastTimestamp === 0 || isUserInteraction ? timestamp : lastTimestamp;
|
|
5475
|
+
|
|
5476
|
+
this._setWindowId(windowId);
|
|
5477
|
+
|
|
5478
|
+
this._setSessionId(sessionId, newTimestamp);
|
|
5479
|
+
|
|
5480
|
+
return {
|
|
5481
|
+
sessionId: sessionId,
|
|
5482
|
+
windowId: windowId
|
|
5483
|
+
};
|
|
5484
|
+
}
|
|
5485
|
+
}]);
|
|
5486
|
+
|
|
5487
|
+
return SessionIdManager;
|
|
5488
|
+
}();
|
|
5489
|
+
|
|
5321
5490
|
/*
|
|
5322
5491
|
SIMPLE STYLE GUIDE:
|
|
5323
5492
|
|
|
@@ -5481,7 +5650,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
5481
5650
|
// global debug to be true
|
|
5482
5651
|
|
|
5483
5652
|
|
|
5484
|
-
Config.DEBUG = Config.DEBUG || instance.get_config('debug'); // if target is not defined, we called init after the lib already
|
|
5653
|
+
Config$1.DEBUG = Config$1.DEBUG || instance.get_config('debug'); // if target is not defined, we called init after the lib already
|
|
5485
5654
|
// loaded, so there won't be an array of things to execute
|
|
5486
5655
|
|
|
5487
5656
|
if (!_.isUndefined(target) && _.isArray(target)) {
|
|
@@ -5558,6 +5727,7 @@ PostHogLib.prototype._init = function (token, config, name) {
|
|
|
5558
5727
|
this.__captureHooks = [];
|
|
5559
5728
|
this.__request_queue = [];
|
|
5560
5729
|
this['persistence'] = new PostHogPersistence(this['config']);
|
|
5730
|
+
this['_sessionIdManager'] = new SessionIdManager(this['config'], this['persistence']);
|
|
5561
5731
|
|
|
5562
5732
|
this._gdpr_init();
|
|
5563
5733
|
|
|
@@ -5917,7 +6087,7 @@ PostHogLib.prototype.capture = addOptOutCheckPostHogLib(function (event_name, pr
|
|
|
5917
6087
|
this.__compress_and_send_json_request(url, jsonData, options);
|
|
5918
6088
|
}
|
|
5919
6089
|
|
|
5920
|
-
this._invokeCaptureHooks(event_name);
|
|
6090
|
+
this._invokeCaptureHooks(event_name, data);
|
|
5921
6091
|
|
|
5922
6092
|
return data;
|
|
5923
6093
|
});
|
|
@@ -5926,8 +6096,8 @@ PostHogLib.prototype._addCaptureHook = function (callback) {
|
|
|
5926
6096
|
this.__captureHooks.push(callback);
|
|
5927
6097
|
};
|
|
5928
6098
|
|
|
5929
|
-
PostHogLib.prototype._invokeCaptureHooks = function (eventName) {
|
|
5930
|
-
this.config._onCapture(eventName);
|
|
6099
|
+
PostHogLib.prototype._invokeCaptureHooks = function (eventName, eventData) {
|
|
6100
|
+
this.config._onCapture(eventName, eventData);
|
|
5931
6101
|
|
|
5932
6102
|
_.each(this.__captureHooks, function (callback) {
|
|
5933
6103
|
return callback(eventName);
|
|
@@ -5949,6 +6119,15 @@ PostHogLib.prototype._calculate_event_properties = function (event_name, event_p
|
|
|
5949
6119
|
if (!_.isUndefined(start_timestamp)) {
|
|
5950
6120
|
var duration_in_ms = new Date().getTime() - start_timestamp;
|
|
5951
6121
|
properties['$duration'] = parseFloat((duration_in_ms / 1000).toFixed(3));
|
|
6122
|
+
}
|
|
6123
|
+
|
|
6124
|
+
if (this._sessionIdManager) {
|
|
6125
|
+
var _this$_sessionIdManag = this._sessionIdManager.getSessionAndWindowId(),
|
|
6126
|
+
sessionId = _this$_sessionIdManag.sessionId,
|
|
6127
|
+
windowId = _this$_sessionIdManag.windowId;
|
|
6128
|
+
|
|
6129
|
+
properties['$session_id'] = sessionId;
|
|
6130
|
+
properties['$window_id'] = windowId;
|
|
5952
6131
|
} // note: extend writes to the first object, so lets make sure we
|
|
5953
6132
|
// don't write to the persistence properties object and info
|
|
5954
6133
|
// properties object by passing in a new object
|
|
@@ -6187,12 +6366,20 @@ PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet,
|
|
|
6187
6366
|
}
|
|
6188
6367
|
|
|
6189
6368
|
this.reloadFeatureFlags();
|
|
6190
|
-
};
|
|
6191
|
-
|
|
6369
|
+
};
|
|
6370
|
+
/**
|
|
6371
|
+
* Alpha feature: don't use unless you know what you're doing!
|
|
6372
|
+
*
|
|
6373
|
+
* Sets group analytics information for subsequent events.
|
|
6374
|
+
*
|
|
6375
|
+
* @param {String} groupType Group type (example: 'organization')
|
|
6376
|
+
* @param {String} groupKey Group key (example: 'org::5')
|
|
6377
|
+
* @param {Object} groupPropertiesToSet Optional properties to set for group
|
|
6378
|
+
*/
|
|
6192
6379
|
|
|
6193
|
-
PostHogLib.prototype.__group = function (groupType, groupKey, groupPropertiesToSet) {
|
|
6194
|
-
console$1.error('posthog.__group is still under development and should not be used in production!');
|
|
6195
6380
|
|
|
6381
|
+
PostHogLib.prototype.group = function (groupType, groupKey, groupPropertiesToSet) {
|
|
6382
|
+
// console.error('posthog.group is still under development and should not be used in production!')
|
|
6196
6383
|
if (!groupType || !groupKey) {
|
|
6197
6384
|
console$1.error('posthog.group requires a group type and group key');
|
|
6198
6385
|
return;
|
|
@@ -6204,15 +6391,14 @@ PostHogLib.prototype.__group = function (groupType, groupKey, groupPropertiesToS
|
|
|
6204
6391
|
this.register({
|
|
6205
6392
|
$groups: _objectSpread2(_objectSpread2({}, existingGroups), {}, _defineProperty({}, groupType, groupKey))
|
|
6206
6393
|
});
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
$
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
$
|
|
6213
|
-
}
|
|
6214
|
-
}
|
|
6215
|
-
this.reloadFeatureFlags();
|
|
6394
|
+
|
|
6395
|
+
if (groupPropertiesToSet) {
|
|
6396
|
+
this.capture('$groupidentify', {
|
|
6397
|
+
$group_type: groupType,
|
|
6398
|
+
$group_key: groupKey,
|
|
6399
|
+
$group_set: groupPropertiesToSet
|
|
6400
|
+
});
|
|
6401
|
+
}
|
|
6216
6402
|
};
|
|
6217
6403
|
/**
|
|
6218
6404
|
* Clears super properties and generates a new random distinct_id for this instance.
|
|
@@ -6254,7 +6440,7 @@ PostHogLib.prototype.get_distinct_id = function () {
|
|
|
6254
6440
|
};
|
|
6255
6441
|
|
|
6256
6442
|
PostHogLib.prototype.getGroups = function () {
|
|
6257
|
-
return this.get_property('groups');
|
|
6443
|
+
return this.get_property('$groups') || {};
|
|
6258
6444
|
};
|
|
6259
6445
|
/**
|
|
6260
6446
|
* Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively).
|
|
@@ -6457,7 +6643,7 @@ PostHogLib.prototype.set_config = function (config) {
|
|
|
6457
6643
|
this['config']['debug'] = true;
|
|
6458
6644
|
}
|
|
6459
6645
|
|
|
6460
|
-
Config.DEBUG = Config.DEBUG || this.get_config('debug');
|
|
6646
|
+
Config$1.DEBUG = Config$1.DEBUG || this.get_config('debug');
|
|
6461
6647
|
|
|
6462
6648
|
if (this.sessionRecording && typeof config.disable_session_recording !== 'undefined') {
|
|
6463
6649
|
if (oldConfig.disable_session_recording !== config.disable_session_recording) {
|
|
@@ -6845,7 +7031,7 @@ PostHogLib.prototype['register'] = PostHogLib.prototype.register;
|
|
|
6845
7031
|
PostHogLib.prototype['register_once'] = PostHogLib.prototype.register_once;
|
|
6846
7032
|
PostHogLib.prototype['unregister'] = PostHogLib.prototype.unregister;
|
|
6847
7033
|
PostHogLib.prototype['identify'] = PostHogLib.prototype.identify;
|
|
6848
|
-
PostHogLib.prototype['
|
|
7034
|
+
PostHogLib.prototype['group'] = PostHogLib.prototype.group;
|
|
6849
7035
|
PostHogLib.prototype['alias'] = PostHogLib.prototype.alias;
|
|
6850
7036
|
PostHogLib.prototype['set_config'] = PostHogLib.prototype.set_config;
|
|
6851
7037
|
PostHogLib.prototype['get_config'] = PostHogLib.prototype.get_config;
|
|
@@ -6869,7 +7055,7 @@ PostHogLib.prototype['onFeatureFlags'] = PostHogLib.prototype.onFeatureFlags;
|
|
|
6869
7055
|
PostHogLib.prototype['decodeLZ64'] = PostHogLib.prototype.decodeLZ64;
|
|
6870
7056
|
PostHogLib.prototype['SentryIntegration'] = PostHogLib.prototype.sentry_integration;
|
|
6871
7057
|
PostHogLib.prototype['debug'] = PostHogLib.prototype.debug;
|
|
6872
|
-
PostHogLib.prototype['LIB_VERSION'] = Config.LIB_VERSION;
|
|
7058
|
+
PostHogLib.prototype['LIB_VERSION'] = Config$1.LIB_VERSION;
|
|
6873
7059
|
PostHogLib.prototype['startSessionRecording'] = PostHogLib.prototype.startSessionRecording;
|
|
6874
7060
|
PostHogLib.prototype['stopSessionRecording'] = PostHogLib.prototype.stopSessionRecording;
|
|
6875
7061
|
PostHogLib.prototype['sessionRecordingStarted'] = PostHogLib.prototype.sessionRecordingStarted; // PostHogPersistence Exports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.2",
|
|
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",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"posthog-js": "link:.",
|
|
61
61
|
"prettier": "^2.0.5",
|
|
62
62
|
"rollup": "^2.18.2",
|
|
63
|
-
"rrweb": "^1.0.
|
|
63
|
+
"rrweb": "^1.0.6",
|
|
64
64
|
"sinon": "9.0.2",
|
|
65
65
|
"testcafe": "^1.10.1",
|
|
66
66
|
"testcafe-browser-provider-browserstack": "^1.13.2-alpha.1",
|