posthog-js 1.15.4 → 1.16.3
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 +17 -0
- package/README.md +0 -2
- package/dist/array.js +12 -12
- package/dist/es.js +252 -66
- package/dist/module.d.ts +11 -0
- package/dist/module.js +252 -66
- package/package.json +2 -2
package/dist/es.js
CHANGED
|
@@ -863,9 +863,9 @@ var LZString = {
|
|
|
863
863
|
}
|
|
864
864
|
};
|
|
865
865
|
|
|
866
|
-
var version = "1.
|
|
866
|
+
var version = "1.16.3";
|
|
867
867
|
|
|
868
|
-
var Config = {
|
|
868
|
+
var Config$1 = {
|
|
869
869
|
DEBUG: false,
|
|
870
870
|
LIB_VERSION: version
|
|
871
871
|
};
|
|
@@ -903,7 +903,7 @@ var _ = {
|
|
|
903
903
|
var console$1 = {
|
|
904
904
|
/** @type {function(...*)} */
|
|
905
905
|
log: function log() {
|
|
906
|
-
if (Config.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
906
|
+
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
907
907
|
try {
|
|
908
908
|
window.console.log.apply(window.console, arguments);
|
|
909
909
|
} catch (err) {
|
|
@@ -916,7 +916,7 @@ var console$1 = {
|
|
|
916
916
|
|
|
917
917
|
/** @type {function(...*)} */
|
|
918
918
|
error: function error() {
|
|
919
|
-
if (Config.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
919
|
+
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
920
920
|
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments));
|
|
921
921
|
|
|
922
922
|
try {
|
|
@@ -1140,7 +1140,7 @@ _.safewrap = function (f) {
|
|
|
1140
1140
|
} catch (e) {
|
|
1141
1141
|
console$1.critical('Implementation error. Please turn on debug and contact support@posthog.com.');
|
|
1142
1142
|
|
|
1143
|
-
if (Config.DEBUG) {
|
|
1143
|
+
if (Config$1.DEBUG) {
|
|
1144
1144
|
console$1.critical(e);
|
|
1145
1145
|
}
|
|
1146
1146
|
}
|
|
@@ -1734,7 +1734,7 @@ _.info = {
|
|
|
1734
1734
|
$viewport_height: window.innerHeight,
|
|
1735
1735
|
$viewport_width: window.innerWidth,
|
|
1736
1736
|
$lib: 'web',
|
|
1737
|
-
$lib_version: Config.LIB_VERSION,
|
|
1737
|
+
$lib_version: Config$1.LIB_VERSION,
|
|
1738
1738
|
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
|
|
1739
1739
|
$time: _.timestamp() / 1000 // epoch time in seconds
|
|
1740
1740
|
|
|
@@ -2006,16 +2006,16 @@ function shouldCaptureValue(value) {
|
|
|
2006
2006
|
return true;
|
|
2007
2007
|
}
|
|
2008
2008
|
/*
|
|
2009
|
-
* Check whether an attribute name is an Angular
|
|
2009
|
+
* Check whether an attribute name is an Angular style attr (either _ngcontent or _nghost)
|
|
2010
2010
|
* These update on each build and lead to noise in the element chain
|
|
2011
|
-
* https://
|
|
2011
|
+
* More details on the attributes here: https://angular.io/guide/view-encapsulation
|
|
2012
2012
|
* @param {string} attributeName - string value to check
|
|
2013
2013
|
* @returns {boolean} whether the element is an angular tag
|
|
2014
2014
|
*/
|
|
2015
2015
|
|
|
2016
|
-
function
|
|
2016
|
+
function isAngularStyleAttr(attributeName) {
|
|
2017
2017
|
if (typeof attributeName === 'string') {
|
|
2018
|
-
return attributeName.substring(0, 10) === '_ngcontent';
|
|
2018
|
+
return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost';
|
|
2019
2019
|
}
|
|
2020
2020
|
|
|
2021
2021
|
return false;
|
|
@@ -2116,7 +2116,7 @@ var autocapture = {
|
|
|
2116
2116
|
// Only capture attributes we know are safe
|
|
2117
2117
|
if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1) return;
|
|
2118
2118
|
|
|
2119
|
-
if (!maskInputs && shouldCaptureValue(attr.value) && !
|
|
2119
|
+
if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)) {
|
|
2120
2120
|
props['attr__' + attr.name] = attr.value;
|
|
2121
2121
|
}
|
|
2122
2122
|
});
|
|
@@ -2537,6 +2537,73 @@ var memoryStore = {
|
|
|
2537
2537
|
remove: function remove(name) {
|
|
2538
2538
|
delete memoryStorage[name];
|
|
2539
2539
|
}
|
|
2540
|
+
}; // Storage that only lasts the length of a tab/window. Survives page refreshes
|
|
2541
|
+
|
|
2542
|
+
var sessionStore = {
|
|
2543
|
+
sessionStorageSupported: null,
|
|
2544
|
+
is_supported: function is_supported() {
|
|
2545
|
+
if (sessionStore.sessionStorageSupported !== null) {
|
|
2546
|
+
return sessionStore.sessionStorageSupported;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
sessionStore.sessionStorageSupported = true;
|
|
2550
|
+
|
|
2551
|
+
if (window) {
|
|
2552
|
+
try {
|
|
2553
|
+
var key = '__support__',
|
|
2554
|
+
val = 'xyz';
|
|
2555
|
+
sessionStore.set(key, val);
|
|
2556
|
+
|
|
2557
|
+
if (sessionStore.get(key) !== '"xyz"') {
|
|
2558
|
+
sessionStore.sessionStorageSupported = false;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
sessionStore.remove(key);
|
|
2562
|
+
} catch (err) {
|
|
2563
|
+
sessionStore.sessionStorageSupported = false;
|
|
2564
|
+
}
|
|
2565
|
+
} else {
|
|
2566
|
+
sessionStore.sessionStorageSupported = false;
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
return sessionStore.sessionStorageSupported;
|
|
2570
|
+
},
|
|
2571
|
+
error: function error(msg) {
|
|
2572
|
+
if (Config.DEBUG) {
|
|
2573
|
+
console$1.error('sessionStorage error: ', msg);
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
get: function get(name) {
|
|
2577
|
+
try {
|
|
2578
|
+
return window.sessionStorage.getItem(name);
|
|
2579
|
+
} catch (err) {
|
|
2580
|
+
sessionStore.error(err);
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
return null;
|
|
2584
|
+
},
|
|
2585
|
+
parse: function parse(name) {
|
|
2586
|
+
try {
|
|
2587
|
+
return JSON.parse(sessionStore.get(name)) || null;
|
|
2588
|
+
} catch (err) {// noop
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
return null;
|
|
2592
|
+
},
|
|
2593
|
+
set: function set(name, value) {
|
|
2594
|
+
try {
|
|
2595
|
+
window.sessionStorage.setItem(name, JSON.stringify(value));
|
|
2596
|
+
} catch (err) {
|
|
2597
|
+
sessionStore.error(err);
|
|
2598
|
+
}
|
|
2599
|
+
},
|
|
2600
|
+
remove: function remove(name) {
|
|
2601
|
+
try {
|
|
2602
|
+
window.sessionStorage.removeItem(name);
|
|
2603
|
+
} catch (err) {
|
|
2604
|
+
sessionStore.error(err);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2540
2607
|
};
|
|
2541
2608
|
|
|
2542
2609
|
/**
|
|
@@ -3512,28 +3579,6 @@ PostHogPersistence.prototype.remove_event_timer = function (event_name) {
|
|
|
3512
3579
|
return timestamp;
|
|
3513
3580
|
};
|
|
3514
3581
|
|
|
3515
|
-
var SESSION_CHANGE_THRESHOLD = 30 * 60 * 1000; // 30 mins
|
|
3516
|
-
|
|
3517
|
-
var sessionIdGenerator = (function (persistence, timestamp) {
|
|
3518
|
-
var _ref = persistence['props'][SESSION_ID] || [0, null],
|
|
3519
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
3520
|
-
lastTimestamp = _ref2[0],
|
|
3521
|
-
sessionId = _ref2[1];
|
|
3522
|
-
|
|
3523
|
-
var isNewSessionId = false;
|
|
3524
|
-
|
|
3525
|
-
if (Math.abs(timestamp - lastTimestamp) > SESSION_CHANGE_THRESHOLD) {
|
|
3526
|
-
sessionId = _.UUID();
|
|
3527
|
-
isNewSessionId = true;
|
|
3528
|
-
}
|
|
3529
|
-
|
|
3530
|
-
persistence.register(_defineProperty({}, SESSION_ID, [timestamp, sessionId]));
|
|
3531
|
-
return {
|
|
3532
|
-
isNewSessionId: isNewSessionId,
|
|
3533
|
-
sessionId: sessionId
|
|
3534
|
-
};
|
|
3535
|
-
});
|
|
3536
|
-
|
|
3537
3582
|
var replacementImageURI = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg==';
|
|
3538
3583
|
/*
|
|
3539
3584
|
* Check whether a data payload is nearing 5mb. If it is, it checks the data for
|
|
@@ -3585,6 +3630,10 @@ function filterDataURLsFromLargeDataObjects(data) {
|
|
|
3585
3630
|
}
|
|
3586
3631
|
|
|
3587
3632
|
var BASE_ENDPOINT = '/e/';
|
|
3633
|
+
var FULL_SNAPSHOT_EVENT_TYPE = 2;
|
|
3634
|
+
var META_EVENT_TYPE = 4;
|
|
3635
|
+
var INCREMENTAL_SNAPSHOT_EVENT_TYPE = 3;
|
|
3636
|
+
var MUTATION_SOURCE_TYPE = 3;
|
|
3588
3637
|
var SessionRecording = /*#__PURE__*/function () {
|
|
3589
3638
|
function SessionRecording(instance) {
|
|
3590
3639
|
_classCallCheck(this, SessionRecording);
|
|
@@ -3595,6 +3644,8 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3595
3644
|
this.emit = false;
|
|
3596
3645
|
this.endpoint = BASE_ENDPOINT;
|
|
3597
3646
|
this.stopRrweb = null;
|
|
3647
|
+
this.windowId = null;
|
|
3648
|
+
this.sessionId = null;
|
|
3598
3649
|
}
|
|
3599
3650
|
|
|
3600
3651
|
_createClass(SessionRecording, [{
|
|
@@ -3664,9 +3715,24 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3664
3715
|
|
|
3665
3716
|
if (!this.captureStarted && !this.instance.get_config('disable_session_recording')) {
|
|
3666
3717
|
this.captureStarted = true;
|
|
3667
|
-
loadScript(this.instance.get_config('api_host') + '/static/recorder.js?v=' + Config.LIB_VERSION, _.bind(this._onScriptLoaded, this));
|
|
3718
|
+
loadScript(this.instance.get_config('api_host') + '/static/recorder.js?v=' + Config$1.LIB_VERSION, _.bind(this._onScriptLoaded, this));
|
|
3668
3719
|
}
|
|
3669
3720
|
}
|
|
3721
|
+
}, {
|
|
3722
|
+
key: "_updateWindowAndSessionIds",
|
|
3723
|
+
value: function _updateWindowAndSessionIds(event) {
|
|
3724
|
+
var _this$instance$_sessi = this.instance._sessionIdManager.getSessionAndWindowId(event.timestamp || new Date().getTime(), event),
|
|
3725
|
+
windowId = _this$instance$_sessi.windowId,
|
|
3726
|
+
sessionId = _this$instance$_sessi.sessionId; // Event types FullSnapshot and Meta mean we're already in the process of sending a full snapshot
|
|
3727
|
+
|
|
3728
|
+
|
|
3729
|
+
if ((this.windowId !== windowId || this.sessionId !== sessionId) && [FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1) {
|
|
3730
|
+
window.rrweb.record.takeFullSnapshot();
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
this.windowId = windowId;
|
|
3734
|
+
this.sessionId = sessionId;
|
|
3735
|
+
}
|
|
3670
3736
|
}, {
|
|
3671
3737
|
key: "_onScriptLoaded",
|
|
3672
3738
|
value: function _onScriptLoaded() {
|
|
@@ -3699,23 +3765,20 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3699
3765
|
}
|
|
3700
3766
|
|
|
3701
3767
|
this.stopRrweb = window.rrweb.record(_objectSpread2({
|
|
3702
|
-
emit: function emit(
|
|
3703
|
-
|
|
3704
|
-
var sessionIdObject = sessionIdGenerator(_this2.instance.persistence, data.timestamp); // Data type 2 and 4 are FullSnapshot and Meta and they mean we're already
|
|
3705
|
-
// in the process of sending a full snapshot
|
|
3768
|
+
emit: function emit(event) {
|
|
3769
|
+
event = filterDataURLsFromLargeDataObjects(event);
|
|
3706
3770
|
|
|
3707
|
-
|
|
3708
|
-
window.rrweb.record.takeFullSnapshot();
|
|
3709
|
-
}
|
|
3771
|
+
_this2._updateWindowAndSessionIds(event);
|
|
3710
3772
|
|
|
3711
3773
|
var properties = {
|
|
3712
|
-
$snapshot_data:
|
|
3713
|
-
$session_id:
|
|
3774
|
+
$snapshot_data: event,
|
|
3775
|
+
$session_id: _this2.sessionId,
|
|
3776
|
+
$window_id: _this2.windowId
|
|
3714
3777
|
};
|
|
3715
3778
|
|
|
3716
3779
|
_this2.instance._captureMetrics.incr('rrweb-record');
|
|
3717
3780
|
|
|
3718
|
-
_this2.instance._captureMetrics.incr("rrweb-record-".concat(
|
|
3781
|
+
_this2.instance._captureMetrics.incr("rrweb-record-".concat(event.type));
|
|
3719
3782
|
|
|
3720
3783
|
if (_this2.emit) {
|
|
3721
3784
|
_this2._captureSnapshot(properties);
|
|
@@ -3746,7 +3809,7 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3746
3809
|
_noTruncate: true,
|
|
3747
3810
|
_batchKey: 'sessionRecording',
|
|
3748
3811
|
_metrics: {
|
|
3749
|
-
rrweb_full_snapshot: properties.$snapshot_data.type ===
|
|
3812
|
+
rrweb_full_snapshot: properties.$snapshot_data.type === FULL_SNAPSHOT_EVENT_TYPE
|
|
3750
3813
|
}
|
|
3751
3814
|
});
|
|
3752
3815
|
}
|
|
@@ -5316,6 +5379,112 @@ var RetryQueue = /*#__PURE__*/function (_RequestQueueScaffold) {
|
|
|
5316
5379
|
return RetryQueue;
|
|
5317
5380
|
}(RequestQueueScaffold);
|
|
5318
5381
|
|
|
5382
|
+
var SESSION_CHANGE_THRESHOLD = 30 * 60 * 1000; // 30 mins
|
|
5383
|
+
|
|
5384
|
+
var SessionIdManager = /*#__PURE__*/function () {
|
|
5385
|
+
function SessionIdManager(config, persistence) {
|
|
5386
|
+
_classCallCheck(this, SessionIdManager);
|
|
5387
|
+
|
|
5388
|
+
this.persistence = persistence;
|
|
5389
|
+
|
|
5390
|
+
if (config['persistence_name']) {
|
|
5391
|
+
this.window_id_storage_key = 'ph_' + config['persistence_name'] + '_window_id';
|
|
5392
|
+
} else {
|
|
5393
|
+
this.window_id_storage_key = 'ph_' + config['token'] + '_window_id';
|
|
5394
|
+
}
|
|
5395
|
+
} // Note: this tries to store the windowId in sessionStorage. SessionStorage is unique to the current window/tab,
|
|
5396
|
+
// and persists page loads/reloads. So it's uniquely suited for storing the windowId. This function also respects
|
|
5397
|
+
// when persistence is disabled (by user config) and when sessionStorage is not supported (it *should* be supported on all browsers),
|
|
5398
|
+
// and in that case, it falls back to memory (which sadly, won't persist page loads)
|
|
5399
|
+
|
|
5400
|
+
|
|
5401
|
+
_createClass(SessionIdManager, [{
|
|
5402
|
+
key: "_setWindowId",
|
|
5403
|
+
value: function _setWindowId(windowId) {
|
|
5404
|
+
if (windowId !== this.windowId) {
|
|
5405
|
+
this.windowId = windowId;
|
|
5406
|
+
|
|
5407
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5408
|
+
sessionStore.set(this.window_id_storage_key, windowId);
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5411
|
+
}
|
|
5412
|
+
}, {
|
|
5413
|
+
key: "_getWindowId",
|
|
5414
|
+
value: function _getWindowId() {
|
|
5415
|
+
if (this.windowId) {
|
|
5416
|
+
return this.windowId;
|
|
5417
|
+
}
|
|
5418
|
+
|
|
5419
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
5420
|
+
return sessionStore.parse(this.window_id_storage_key);
|
|
5421
|
+
}
|
|
5422
|
+
|
|
5423
|
+
return null;
|
|
5424
|
+
} // Note: 'this.persistence.register' can be disabled in the config.
|
|
5425
|
+
// In that case, this works by storing sessionId and the timestamp in memory.
|
|
5426
|
+
|
|
5427
|
+
}, {
|
|
5428
|
+
key: "_setSessionId",
|
|
5429
|
+
value: function _setSessionId(sessionId, timestamp) {
|
|
5430
|
+
if (sessionId !== this.sessionId || timestamp !== this.timestamp) {
|
|
5431
|
+
this.timestamp = timestamp;
|
|
5432
|
+
this.sessionId = sessionId;
|
|
5433
|
+
this.persistence.register(_defineProperty({}, SESSION_ID, [timestamp, sessionId]));
|
|
5434
|
+
}
|
|
5435
|
+
}
|
|
5436
|
+
}, {
|
|
5437
|
+
key: "_getSessionId",
|
|
5438
|
+
value: function _getSessionId() {
|
|
5439
|
+
if (this.sessionId && this.timestamp) {
|
|
5440
|
+
return [this.timestamp, this.sessionId];
|
|
5441
|
+
}
|
|
5442
|
+
|
|
5443
|
+
return this.persistence['props'][SESSION_ID] || [0, null];
|
|
5444
|
+
}
|
|
5445
|
+
}, {
|
|
5446
|
+
key: "getSessionAndWindowId",
|
|
5447
|
+
value: function getSessionAndWindowId() {
|
|
5448
|
+
var _recordingEvent$data;
|
|
5449
|
+
|
|
5450
|
+
var timestamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
5451
|
+
var recordingEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
5452
|
+
// Some recording events are triggered by non-user events (e.g. "X minutes ago" text updating on the screen).
|
|
5453
|
+
// We don't want to update the session and window ids in these cases. These events are designated by event
|
|
5454
|
+
// type -> incremental update, and source -> mutation.
|
|
5455
|
+
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);
|
|
5456
|
+
timestamp = timestamp || new Date().getTime();
|
|
5457
|
+
|
|
5458
|
+
var _this$_getSessionId = this._getSessionId(),
|
|
5459
|
+
_this$_getSessionId2 = _slicedToArray(_this$_getSessionId, 2),
|
|
5460
|
+
lastTimestamp = _this$_getSessionId2[0],
|
|
5461
|
+
sessionId = _this$_getSessionId2[1];
|
|
5462
|
+
|
|
5463
|
+
var windowId = this._getWindowId();
|
|
5464
|
+
|
|
5465
|
+
if (!sessionId || isUserInteraction && Math.abs(timestamp - lastTimestamp) > SESSION_CHANGE_THRESHOLD) {
|
|
5466
|
+
sessionId = _.UUID();
|
|
5467
|
+
windowId = _.UUID();
|
|
5468
|
+
} else if (!windowId) {
|
|
5469
|
+
windowId = _.UUID();
|
|
5470
|
+
}
|
|
5471
|
+
|
|
5472
|
+
var newTimestamp = lastTimestamp === 0 || isUserInteraction ? timestamp : lastTimestamp;
|
|
5473
|
+
|
|
5474
|
+
this._setWindowId(windowId);
|
|
5475
|
+
|
|
5476
|
+
this._setSessionId(sessionId, newTimestamp);
|
|
5477
|
+
|
|
5478
|
+
return {
|
|
5479
|
+
sessionId: sessionId,
|
|
5480
|
+
windowId: windowId
|
|
5481
|
+
};
|
|
5482
|
+
}
|
|
5483
|
+
}]);
|
|
5484
|
+
|
|
5485
|
+
return SessionIdManager;
|
|
5486
|
+
}();
|
|
5487
|
+
|
|
5319
5488
|
/*
|
|
5320
5489
|
SIMPLE STYLE GUIDE:
|
|
5321
5490
|
|
|
@@ -5479,7 +5648,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
5479
5648
|
// global debug to be true
|
|
5480
5649
|
|
|
5481
5650
|
|
|
5482
|
-
Config.DEBUG = Config.DEBUG || instance.get_config('debug'); // if target is not defined, we called init after the lib already
|
|
5651
|
+
Config$1.DEBUG = Config$1.DEBUG || instance.get_config('debug'); // if target is not defined, we called init after the lib already
|
|
5483
5652
|
// loaded, so there won't be an array of things to execute
|
|
5484
5653
|
|
|
5485
5654
|
if (!_.isUndefined(target) && _.isArray(target)) {
|
|
@@ -5556,6 +5725,7 @@ PostHogLib.prototype._init = function (token, config, name) {
|
|
|
5556
5725
|
this.__captureHooks = [];
|
|
5557
5726
|
this.__request_queue = [];
|
|
5558
5727
|
this['persistence'] = new PostHogPersistence(this['config']);
|
|
5728
|
+
this['_sessionIdManager'] = new SessionIdManager(this['config'], this['persistence']);
|
|
5559
5729
|
|
|
5560
5730
|
this._gdpr_init();
|
|
5561
5731
|
|
|
@@ -5915,7 +6085,7 @@ PostHogLib.prototype.capture = addOptOutCheckPostHogLib(function (event_name, pr
|
|
|
5915
6085
|
this.__compress_and_send_json_request(url, jsonData, options);
|
|
5916
6086
|
}
|
|
5917
6087
|
|
|
5918
|
-
this._invokeCaptureHooks(event_name);
|
|
6088
|
+
this._invokeCaptureHooks(event_name, data);
|
|
5919
6089
|
|
|
5920
6090
|
return data;
|
|
5921
6091
|
});
|
|
@@ -5924,8 +6094,8 @@ PostHogLib.prototype._addCaptureHook = function (callback) {
|
|
|
5924
6094
|
this.__captureHooks.push(callback);
|
|
5925
6095
|
};
|
|
5926
6096
|
|
|
5927
|
-
PostHogLib.prototype._invokeCaptureHooks = function (eventName) {
|
|
5928
|
-
this.config._onCapture(eventName);
|
|
6097
|
+
PostHogLib.prototype._invokeCaptureHooks = function (eventName, eventData) {
|
|
6098
|
+
this.config._onCapture(eventName, eventData);
|
|
5929
6099
|
|
|
5930
6100
|
_.each(this.__captureHooks, function (callback) {
|
|
5931
6101
|
return callback(eventName);
|
|
@@ -5947,6 +6117,15 @@ PostHogLib.prototype._calculate_event_properties = function (event_name, event_p
|
|
|
5947
6117
|
if (!_.isUndefined(start_timestamp)) {
|
|
5948
6118
|
var duration_in_ms = new Date().getTime() - start_timestamp;
|
|
5949
6119
|
properties['$duration'] = parseFloat((duration_in_ms / 1000).toFixed(3));
|
|
6120
|
+
}
|
|
6121
|
+
|
|
6122
|
+
if (this._sessionIdManager) {
|
|
6123
|
+
var _this$_sessionIdManag = this._sessionIdManager.getSessionAndWindowId(),
|
|
6124
|
+
sessionId = _this$_sessionIdManag.sessionId,
|
|
6125
|
+
windowId = _this$_sessionIdManag.windowId;
|
|
6126
|
+
|
|
6127
|
+
properties['$session_id'] = sessionId;
|
|
6128
|
+
properties['$window_id'] = windowId;
|
|
5950
6129
|
} // note: extend writes to the first object, so lets make sure we
|
|
5951
6130
|
// don't write to the persistence properties object and info
|
|
5952
6131
|
// properties object by passing in a new object
|
|
@@ -6185,12 +6364,20 @@ PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet,
|
|
|
6185
6364
|
}
|
|
6186
6365
|
|
|
6187
6366
|
this.reloadFeatureFlags();
|
|
6188
|
-
};
|
|
6189
|
-
|
|
6367
|
+
};
|
|
6368
|
+
/**
|
|
6369
|
+
* Alpha feature: don't use unless you know what you're doing!
|
|
6370
|
+
*
|
|
6371
|
+
* Sets group analytics information for subsequent events.
|
|
6372
|
+
*
|
|
6373
|
+
* @param {String} groupType Group type (example: 'organization')
|
|
6374
|
+
* @param {String} groupKey Group key (example: 'org::5')
|
|
6375
|
+
* @param {Object} groupPropertiesToSet Optional properties to set for group
|
|
6376
|
+
*/
|
|
6190
6377
|
|
|
6191
|
-
PostHogLib.prototype.__group = function (groupType, groupKey, groupPropertiesToSet) {
|
|
6192
|
-
console$1.error('posthog.__group is still under development and should not be used in production!');
|
|
6193
6378
|
|
|
6379
|
+
PostHogLib.prototype.group = function (groupType, groupKey, groupPropertiesToSet) {
|
|
6380
|
+
// console.error('posthog.group is still under development and should not be used in production!')
|
|
6194
6381
|
if (!groupType || !groupKey) {
|
|
6195
6382
|
console$1.error('posthog.group requires a group type and group key');
|
|
6196
6383
|
return;
|
|
@@ -6202,15 +6389,14 @@ PostHogLib.prototype.__group = function (groupType, groupKey, groupPropertiesToS
|
|
|
6202
6389
|
this.register({
|
|
6203
6390
|
$groups: _objectSpread2(_objectSpread2({}, existingGroups), {}, _defineProperty({}, groupType, groupKey))
|
|
6204
6391
|
});
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
$
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
$
|
|
6211
|
-
}
|
|
6212
|
-
}
|
|
6213
|
-
this.reloadFeatureFlags();
|
|
6392
|
+
|
|
6393
|
+
if (groupPropertiesToSet) {
|
|
6394
|
+
this.capture('$groupidentify', {
|
|
6395
|
+
$group_type: groupType,
|
|
6396
|
+
$group_key: groupKey,
|
|
6397
|
+
$group_set: groupPropertiesToSet
|
|
6398
|
+
});
|
|
6399
|
+
}
|
|
6214
6400
|
};
|
|
6215
6401
|
/**
|
|
6216
6402
|
* Clears super properties and generates a new random distinct_id for this instance.
|
|
@@ -6252,7 +6438,7 @@ PostHogLib.prototype.get_distinct_id = function () {
|
|
|
6252
6438
|
};
|
|
6253
6439
|
|
|
6254
6440
|
PostHogLib.prototype.getGroups = function () {
|
|
6255
|
-
return this.get_property('groups');
|
|
6441
|
+
return this.get_property('$groups') || {};
|
|
6256
6442
|
};
|
|
6257
6443
|
/**
|
|
6258
6444
|
* Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively).
|
|
@@ -6455,7 +6641,7 @@ PostHogLib.prototype.set_config = function (config) {
|
|
|
6455
6641
|
this['config']['debug'] = true;
|
|
6456
6642
|
}
|
|
6457
6643
|
|
|
6458
|
-
Config.DEBUG = Config.DEBUG || this.get_config('debug');
|
|
6644
|
+
Config$1.DEBUG = Config$1.DEBUG || this.get_config('debug');
|
|
6459
6645
|
|
|
6460
6646
|
if (this.sessionRecording && typeof config.disable_session_recording !== 'undefined') {
|
|
6461
6647
|
if (oldConfig.disable_session_recording !== config.disable_session_recording) {
|
|
@@ -6843,7 +7029,7 @@ PostHogLib.prototype['register'] = PostHogLib.prototype.register;
|
|
|
6843
7029
|
PostHogLib.prototype['register_once'] = PostHogLib.prototype.register_once;
|
|
6844
7030
|
PostHogLib.prototype['unregister'] = PostHogLib.prototype.unregister;
|
|
6845
7031
|
PostHogLib.prototype['identify'] = PostHogLib.prototype.identify;
|
|
6846
|
-
PostHogLib.prototype['
|
|
7032
|
+
PostHogLib.prototype['group'] = PostHogLib.prototype.group;
|
|
6847
7033
|
PostHogLib.prototype['alias'] = PostHogLib.prototype.alias;
|
|
6848
7034
|
PostHogLib.prototype['set_config'] = PostHogLib.prototype.set_config;
|
|
6849
7035
|
PostHogLib.prototype['get_config'] = PostHogLib.prototype.get_config;
|
|
@@ -6867,7 +7053,7 @@ PostHogLib.prototype['onFeatureFlags'] = PostHogLib.prototype.onFeatureFlags;
|
|
|
6867
7053
|
PostHogLib.prototype['decodeLZ64'] = PostHogLib.prototype.decodeLZ64;
|
|
6868
7054
|
PostHogLib.prototype['SentryIntegration'] = PostHogLib.prototype.sentry_integration;
|
|
6869
7055
|
PostHogLib.prototype['debug'] = PostHogLib.prototype.debug;
|
|
6870
|
-
PostHogLib.prototype['LIB_VERSION'] = Config.LIB_VERSION;
|
|
7056
|
+
PostHogLib.prototype['LIB_VERSION'] = Config$1.LIB_VERSION;
|
|
6871
7057
|
PostHogLib.prototype['startSessionRecording'] = PostHogLib.prototype.startSessionRecording;
|
|
6872
7058
|
PostHogLib.prototype['stopSessionRecording'] = PostHogLib.prototype.stopSessionRecording;
|
|
6873
7059
|
PostHogLib.prototype['sessionRecordingStarted'] = PostHogLib.prototype.sessionRecordingStarted; // PostHogPersistence Exports
|
package/dist/module.d.ts
CHANGED
|
@@ -166,6 +166,17 @@ declare class posthog {
|
|
|
166
166
|
*/
|
|
167
167
|
static alias(alias: string, original?: string): posthog.CaptureResult | number
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Alpha feature: don't use unless you know what you're doing!
|
|
171
|
+
*
|
|
172
|
+
* Sets group analytics information for subsequent events.
|
|
173
|
+
*
|
|
174
|
+
* @param {String} groupType Group type (example: 'organization')
|
|
175
|
+
* @param {String} groupKey Group key (example: 'org::5')
|
|
176
|
+
* @param {Object} groupPropertiesToSet Optional properties to set for group
|
|
177
|
+
*/
|
|
178
|
+
static group(groupType: string, groupKey: string, groupPropertiesToSet?: posthog.Properties): void
|
|
179
|
+
|
|
169
180
|
/**
|
|
170
181
|
* Update the configuration of a posthog library instance.
|
|
171
182
|
*
|