posthog-js 1.17.7 → 1.18.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 +14 -0
- package/dist/array.js +9 -9
- package/dist/es.js +117 -64
- package/dist/module.js +117 -64
- package/package.json +5 -4
package/dist/module.js
CHANGED
|
@@ -865,7 +865,7 @@ var LZString = {
|
|
|
865
865
|
}
|
|
866
866
|
};
|
|
867
867
|
|
|
868
|
-
var version = "1.
|
|
868
|
+
var version = "1.18.0";
|
|
869
869
|
|
|
870
870
|
var Config$1 = {
|
|
871
871
|
DEBUG: false,
|
|
@@ -902,15 +902,18 @@ var _ = {
|
|
|
902
902
|
}
|
|
903
903
|
}; // Console override
|
|
904
904
|
|
|
905
|
-
var
|
|
905
|
+
var logger = {
|
|
906
906
|
/** @type {function(...*)} */
|
|
907
907
|
log: function log() {
|
|
908
908
|
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
909
|
+
// Don't log PostHog debug messages in rrweb
|
|
910
|
+
var log = window.console.log['__rrweb_original__'] ? window.console.log['__rrweb_original__'] : window.console.log;
|
|
911
|
+
|
|
909
912
|
try {
|
|
910
|
-
|
|
913
|
+
log.apply(window.console, arguments);
|
|
911
914
|
} catch (err) {
|
|
912
915
|
_.each(arguments, function (arg) {
|
|
913
|
-
|
|
916
|
+
log(arg);
|
|
914
917
|
});
|
|
915
918
|
}
|
|
916
919
|
}
|
|
@@ -919,13 +922,15 @@ var console$1 = {
|
|
|
919
922
|
/** @type {function(...*)} */
|
|
920
923
|
error: function error() {
|
|
921
924
|
if (Config$1.DEBUG && !_.isUndefined(window.console) && window.console) {
|
|
922
|
-
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments));
|
|
925
|
+
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments)); // Don't log PostHog debug messages in rrweb
|
|
926
|
+
|
|
927
|
+
var error = window.console.error['__rrweb_original__'] ? window.console.error['__rrweb_original__'] : window.console.error;
|
|
923
928
|
|
|
924
929
|
try {
|
|
925
|
-
|
|
930
|
+
error.apply(window.console, args);
|
|
926
931
|
} catch (err) {
|
|
927
932
|
_.each(args, function (arg) {
|
|
928
|
-
|
|
933
|
+
error(arg);
|
|
929
934
|
});
|
|
930
935
|
}
|
|
931
936
|
}
|
|
@@ -934,13 +939,15 @@ var console$1 = {
|
|
|
934
939
|
/** @type {function(...*)} */
|
|
935
940
|
critical: function critical() {
|
|
936
941
|
if (!_.isUndefined(window.console) && window.console) {
|
|
937
|
-
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments));
|
|
942
|
+
var args = ['PostHog error:'].concat(Array.prototype.slice.call(arguments)); // Don't log PostHog debug messages in rrweb
|
|
943
|
+
|
|
944
|
+
var error = window.console.error['__rrweb_original__'] ? window.console.error['__rrweb_original__'] : window.console.error;
|
|
938
945
|
|
|
939
946
|
try {
|
|
940
|
-
|
|
947
|
+
error.apply(window.console, args);
|
|
941
948
|
} catch (err) {
|
|
942
949
|
_.each(args, function (arg) {
|
|
943
|
-
|
|
950
|
+
error(arg);
|
|
944
951
|
});
|
|
945
952
|
}
|
|
946
953
|
}
|
|
@@ -1140,10 +1147,10 @@ _.safewrap = function (f) {
|
|
|
1140
1147
|
try {
|
|
1141
1148
|
return f.apply(this, arguments);
|
|
1142
1149
|
} catch (e) {
|
|
1143
|
-
|
|
1150
|
+
logger.critical('Implementation error. Please turn on debug and contact support@posthog.com.');
|
|
1144
1151
|
|
|
1145
1152
|
if (Config$1.DEBUG) {
|
|
1146
|
-
|
|
1153
|
+
logger.critical(e);
|
|
1147
1154
|
}
|
|
1148
1155
|
}
|
|
1149
1156
|
};
|
|
@@ -1434,7 +1441,7 @@ _.getQueryParam = function (url, param) {
|
|
|
1434
1441
|
try {
|
|
1435
1442
|
result = decodeURIComponent(result);
|
|
1436
1443
|
} catch (err) {
|
|
1437
|
-
|
|
1444
|
+
logger.error('Skipping decoding for malformed query param: ' + result);
|
|
1438
1445
|
}
|
|
1439
1446
|
|
|
1440
1447
|
return result.replace(/\+/g, ' ');
|
|
@@ -1463,7 +1470,7 @@ _.register_event = function () {
|
|
|
1463
1470
|
*/
|
|
1464
1471
|
var register_event = function register_event(element, type, handler, oldSchool, useCapture) {
|
|
1465
1472
|
if (!element) {
|
|
1466
|
-
|
|
1473
|
+
logger.error('No valid element provided to register_event');
|
|
1467
1474
|
return;
|
|
1468
1475
|
}
|
|
1469
1476
|
|
|
@@ -2304,7 +2311,7 @@ var autocapture = {
|
|
|
2304
2311
|
var token = instance.get_config('token');
|
|
2305
2312
|
|
|
2306
2313
|
if (this._initializedTokens.indexOf(token) > -1) {
|
|
2307
|
-
|
|
2314
|
+
logger.log('autocapture already initialized for token "' + token + '"');
|
|
2308
2315
|
return;
|
|
2309
2316
|
}
|
|
2310
2317
|
|
|
@@ -2443,14 +2450,14 @@ var localStore = {
|
|
|
2443
2450
|
}
|
|
2444
2451
|
|
|
2445
2452
|
if (!supported) {
|
|
2446
|
-
|
|
2453
|
+
logger.error('localStorage unsupported; falling back to cookie store');
|
|
2447
2454
|
}
|
|
2448
2455
|
|
|
2449
2456
|
_localStorage_supported = supported;
|
|
2450
2457
|
return supported;
|
|
2451
2458
|
},
|
|
2452
2459
|
error: function error(msg) {
|
|
2453
|
-
|
|
2460
|
+
logger.error('localStorage error: ' + msg);
|
|
2454
2461
|
},
|
|
2455
2462
|
get: function get(name) {
|
|
2456
2463
|
try {
|
|
@@ -2541,7 +2548,7 @@ var memoryStore = {
|
|
|
2541
2548
|
return true;
|
|
2542
2549
|
},
|
|
2543
2550
|
error: function error(msg) {
|
|
2544
|
-
|
|
2551
|
+
logger.error('memoryStorage error: ' + msg);
|
|
2545
2552
|
},
|
|
2546
2553
|
parse: function parse(name) {
|
|
2547
2554
|
return memoryStorage[name] || null;
|
|
@@ -2585,7 +2592,7 @@ var sessionStore = {
|
|
|
2585
2592
|
},
|
|
2586
2593
|
error: function error(msg) {
|
|
2587
2594
|
if (Config.DEBUG) {
|
|
2588
|
-
|
|
2595
|
+
logger.error('sessionStorage error: ', msg);
|
|
2589
2596
|
}
|
|
2590
2597
|
},
|
|
2591
2598
|
get: function get(name) {
|
|
@@ -3409,7 +3416,7 @@ var CAMPAIGN_IDS_KEY = '__cmpns';
|
|
|
3409
3416
|
var EVENT_TIMERS_KEY = '__timers';
|
|
3410
3417
|
/** @const */
|
|
3411
3418
|
|
|
3412
|
-
var
|
|
3419
|
+
var SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side';
|
|
3413
3420
|
/** @const */
|
|
3414
3421
|
|
|
3415
3422
|
var SESSION_ID = '$sesid';
|
|
@@ -3418,7 +3425,7 @@ var SESSION_ID = '$sesid';
|
|
|
3418
3425
|
var ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
|
|
3419
3426
|
/** @const */
|
|
3420
3427
|
|
|
3421
|
-
var RESERVED_PROPERTIES = [SET_QUEUE_KEY, SET_ONCE_QUEUE_KEY, UNSET_QUEUE_KEY, ADD_QUEUE_KEY, APPEND_QUEUE_KEY, REMOVE_QUEUE_KEY, UNION_QUEUE_KEY, PEOPLE_DISTINCT_ID_KEY, ALIAS_ID_KEY, CAMPAIGN_IDS_KEY, EVENT_TIMERS_KEY,
|
|
3428
|
+
var RESERVED_PROPERTIES = [SET_QUEUE_KEY, SET_ONCE_QUEUE_KEY, UNSET_QUEUE_KEY, ADD_QUEUE_KEY, APPEND_QUEUE_KEY, REMOVE_QUEUE_KEY, UNION_QUEUE_KEY, PEOPLE_DISTINCT_ID_KEY, ALIAS_ID_KEY, CAMPAIGN_IDS_KEY, EVENT_TIMERS_KEY, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_ID, ENABLED_FEATURE_FLAGS];
|
|
3422
3429
|
/**
|
|
3423
3430
|
* PostHog Persistence Object
|
|
3424
3431
|
* @constructor
|
|
@@ -3445,7 +3452,7 @@ var PostHogPersistence = function PostHogPersistence(config) {
|
|
|
3445
3452
|
var storage_type = config['persistence'];
|
|
3446
3453
|
|
|
3447
3454
|
if (storage_type !== 'cookie' && storage_type.indexOf('localStorage') === -1 && storage_type !== 'memory') {
|
|
3448
|
-
|
|
3455
|
+
logger.critical('Unknown persistence type ' + storage_type + '; falling back to cookie');
|
|
3449
3456
|
storage_type = config['persistence'] = 'cookie';
|
|
3450
3457
|
}
|
|
3451
3458
|
|
|
@@ -3731,18 +3738,22 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3731
3738
|
this.instance = instance;
|
|
3732
3739
|
this.captureStarted = false;
|
|
3733
3740
|
this.snapshots = [];
|
|
3734
|
-
this.emit = false;
|
|
3741
|
+
this.emit = false; // Controls whether data is sent to the server or not
|
|
3742
|
+
|
|
3735
3743
|
this.endpoint = BASE_ENDPOINT;
|
|
3736
3744
|
this.stopRrweb = null;
|
|
3737
3745
|
this.windowId = null;
|
|
3738
3746
|
this.sessionId = null;
|
|
3747
|
+
this.receivedDecide = false;
|
|
3739
3748
|
}
|
|
3740
3749
|
|
|
3741
3750
|
_createClass(SessionRecording, [{
|
|
3742
3751
|
key: "startRecordingIfEnabled",
|
|
3743
3752
|
value: function startRecordingIfEnabled() {
|
|
3744
|
-
if (this.
|
|
3745
|
-
this.
|
|
3753
|
+
if (this.isRecordingEnabled()) {
|
|
3754
|
+
this.startCaptureAndTrySendingQueuedSnapshots();
|
|
3755
|
+
} else {
|
|
3756
|
+
this.stopRecording();
|
|
3746
3757
|
}
|
|
3747
3758
|
}
|
|
3748
3759
|
}, {
|
|
@@ -3759,35 +3770,47 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3759
3770
|
this.captureStarted = false;
|
|
3760
3771
|
}
|
|
3761
3772
|
}
|
|
3773
|
+
}, {
|
|
3774
|
+
key: "isRecordingEnabled",
|
|
3775
|
+
value: function isRecordingEnabled() {
|
|
3776
|
+
var enabled_server_side = !!this.instance.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE);
|
|
3777
|
+
var enabled_client_side = !this.instance.get_config('disable_session_recording');
|
|
3778
|
+
return enabled_server_side && enabled_client_side;
|
|
3779
|
+
}
|
|
3762
3780
|
}, {
|
|
3763
3781
|
key: "afterDecideResponse",
|
|
3764
3782
|
value: function afterDecideResponse(response) {
|
|
3765
|
-
var
|
|
3783
|
+
var _response$sessionReco;
|
|
3784
|
+
|
|
3785
|
+
this.receivedDecide = true;
|
|
3766
3786
|
|
|
3767
3787
|
if (this.instance.persistence) {
|
|
3768
|
-
this.instance.persistence.register(_defineProperty({},
|
|
3788
|
+
this.instance.persistence.register(_defineProperty({}, SESSION_RECORDING_ENABLED_SERVER_SIDE, !!response['sessionRecording']));
|
|
3769
3789
|
}
|
|
3770
3790
|
|
|
3771
|
-
if (
|
|
3772
|
-
|
|
3773
|
-
this.endpoint = response['sessionRecording'].endpoint;
|
|
3774
|
-
}
|
|
3791
|
+
if ((_response$sessionReco = response.sessionRecording) !== null && _response$sessionReco !== void 0 && _response$sessionReco.endpoint) {
|
|
3792
|
+
var _response$sessionReco2;
|
|
3775
3793
|
|
|
3776
|
-
this.
|
|
3794
|
+
this.endpoint = (_response$sessionReco2 = response.sessionRecording) === null || _response$sessionReco2 === void 0 ? void 0 : _response$sessionReco2.endpoint;
|
|
3777
3795
|
}
|
|
3796
|
+
|
|
3797
|
+
this.startRecordingIfEnabled();
|
|
3778
3798
|
}
|
|
3779
3799
|
}, {
|
|
3780
|
-
key: "
|
|
3781
|
-
value: function
|
|
3800
|
+
key: "startCaptureAndTrySendingQueuedSnapshots",
|
|
3801
|
+
value: function startCaptureAndTrySendingQueuedSnapshots() {
|
|
3782
3802
|
var _this = this;
|
|
3783
3803
|
|
|
3784
|
-
|
|
3804
|
+
// Only submit data after we've received a decide response to account for
|
|
3805
|
+
// changing endpoints and the feature being disabled on the server side.
|
|
3806
|
+
if (this.receivedDecide) {
|
|
3807
|
+
this.emit = true;
|
|
3808
|
+
this.snapshots.forEach(function (properties) {
|
|
3809
|
+
return _this._captureSnapshot(properties);
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3785
3812
|
|
|
3786
3813
|
this._startCapture();
|
|
3787
|
-
|
|
3788
|
-
this.snapshots.forEach(function (properties) {
|
|
3789
|
-
return _this._captureSnapshot(properties);
|
|
3790
|
-
});
|
|
3791
3814
|
}
|
|
3792
3815
|
}, {
|
|
3793
3816
|
key: "_startCapture",
|
|
@@ -3817,7 +3840,7 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3817
3840
|
|
|
3818
3841
|
|
|
3819
3842
|
if ((this.windowId !== windowId || this.sessionId !== sessionId) && [FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1) {
|
|
3820
|
-
|
|
3843
|
+
this.rrwebRecord.takeFullSnapshot();
|
|
3821
3844
|
}
|
|
3822
3845
|
|
|
3823
3846
|
this.windowId = windowId;
|
|
@@ -3840,7 +3863,10 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3840
3863
|
maskInputFn: null,
|
|
3841
3864
|
slimDOMOptions: {},
|
|
3842
3865
|
collectFonts: false
|
|
3843
|
-
}; //
|
|
3866
|
+
}; // We switched from loading all of rrweb to just the record part, but
|
|
3867
|
+
// keep backwards compatibility if someone hasn't upgraded PostHog
|
|
3868
|
+
|
|
3869
|
+
this.rrwebRecord = window.rrweb ? window.rrweb.record : window.rrwebRecord; // only allows user to set our 'whitelisted' options
|
|
3844
3870
|
|
|
3845
3871
|
var userSessionRecordingOptions = this.instance.get_config('session_recording');
|
|
3846
3872
|
|
|
@@ -3854,7 +3880,7 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3854
3880
|
}
|
|
3855
3881
|
}
|
|
3856
3882
|
|
|
3857
|
-
this.stopRrweb =
|
|
3883
|
+
this.stopRrweb = this.rrwebRecord(_objectSpread2({
|
|
3858
3884
|
emit: function emit(event) {
|
|
3859
3885
|
event = filterDataURLsFromLargeDataObjects(event);
|
|
3860
3886
|
|
|
@@ -3875,13 +3901,14 @@ var SessionRecording = /*#__PURE__*/function () {
|
|
|
3875
3901
|
} else {
|
|
3876
3902
|
_this2.snapshots.push(properties);
|
|
3877
3903
|
}
|
|
3878
|
-
}
|
|
3904
|
+
},
|
|
3905
|
+
plugins: window.rrwebConsoleRecord && this.instance.get_config('enable_recording_console_log') ? [window.rrwebConsoleRecord.getRecordConsolePlugin()] : []
|
|
3879
3906
|
}, sessionRecordingOptions)); // :TRICKY: rrweb does not capture navigation within SPA-s, so hook into our $pageview events to get access to all events.
|
|
3880
3907
|
// Dropping the initial event is fine (it's always captured by rrweb).
|
|
3881
3908
|
|
|
3882
3909
|
this.instance._addCaptureHook(function (eventName) {
|
|
3883
3910
|
if (eventName === '$pageview') {
|
|
3884
|
-
|
|
3911
|
+
_this2.rrwebRecord.addCustomEvent('$pageview', {
|
|
3885
3912
|
href: window.location.href
|
|
3886
3913
|
});
|
|
3887
3914
|
}
|
|
@@ -5220,7 +5247,7 @@ var xhr = function xhr(_ref) {
|
|
|
5220
5247
|
try {
|
|
5221
5248
|
response = JSON.parse(req.responseText);
|
|
5222
5249
|
} catch (e) {
|
|
5223
|
-
|
|
5250
|
+
logger.error(e);
|
|
5224
5251
|
return;
|
|
5225
5252
|
}
|
|
5226
5253
|
|
|
@@ -5603,9 +5630,33 @@ function deduplicateKeys(performanceEntries) {
|
|
|
5603
5630
|
});
|
|
5604
5631
|
})];
|
|
5605
5632
|
}
|
|
5633
|
+
/*
|
|
5634
|
+
The duration property is on the PerformanceNavigationTiming object.
|
|
5635
|
+
|
|
5636
|
+
It is a timestamp that is the difference between the PerformanceNavigationTiming.loadEventEnd
|
|
5637
|
+
and PerformanceEntry.startTime properties.
|
|
5638
|
+
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
|
5639
|
+
|
|
5640
|
+
Even in browsers that implement it, it is not always available to us
|
|
5641
|
+
*/
|
|
5642
|
+
|
|
5606
5643
|
function pageLoadFrom(performanceData) {
|
|
5607
|
-
var
|
|
5608
|
-
|
|
5644
|
+
var keys = performanceData.navigation && performanceData.navigation[0];
|
|
5645
|
+
var values = performanceData.navigation && performanceData.navigation[1] && performanceData.navigation[1][0];
|
|
5646
|
+
var durationIndex = keys && keys.indexOf('duration');
|
|
5647
|
+
|
|
5648
|
+
if (durationIndex > -1) {
|
|
5649
|
+
return values[durationIndex];
|
|
5650
|
+
} else {
|
|
5651
|
+
var endKeyIndex = keys && keys.indexOf('loadEventEnd');
|
|
5652
|
+
var startKeyIndex = keys && keys.indexOf('startTime'); // start key is not present if start is 0
|
|
5653
|
+
|
|
5654
|
+
if (endKeyIndex > -1) {
|
|
5655
|
+
var end = values && values[endKeyIndex];
|
|
5656
|
+
var start = values && values[startKeyIndex] || 0;
|
|
5657
|
+
return end - start;
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5609
5660
|
}
|
|
5610
5661
|
function getPerformanceData() {
|
|
5611
5662
|
var performanceEntries = {
|
|
@@ -5681,6 +5732,7 @@ var defaultConfig = function defaultConfig() {
|
|
|
5681
5732
|
disable_session_recording: false,
|
|
5682
5733
|
disable_persistence: false,
|
|
5683
5734
|
disable_cookie: false,
|
|
5735
|
+
enable_recording_console_log: false,
|
|
5684
5736
|
secure_cookie: win.location.protocol === 'https:',
|
|
5685
5737
|
ip: true,
|
|
5686
5738
|
opt_out_capturing_by_default: false,
|
|
@@ -5713,7 +5765,7 @@ var defaultConfig = function defaultConfig() {
|
|
|
5713
5765
|
advanced_disable_toolbar_metrics: false,
|
|
5714
5766
|
on_xhr_error: function on_xhr_error(req) {
|
|
5715
5767
|
var error = 'Bad HTTP status: ' + req.status + ' ' + req.statusText;
|
|
5716
|
-
console
|
|
5768
|
+
console.error(error);
|
|
5717
5769
|
},
|
|
5718
5770
|
// Used for internal testing
|
|
5719
5771
|
_onCapture: function _onCapture() {},
|
|
@@ -5745,7 +5797,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
5745
5797
|
instance = target;
|
|
5746
5798
|
} else {
|
|
5747
5799
|
if (target && !_.isArray(target)) {
|
|
5748
|
-
console
|
|
5800
|
+
console.error('You have already initialized ' + name);
|
|
5749
5801
|
return;
|
|
5750
5802
|
}
|
|
5751
5803
|
|
|
@@ -5772,10 +5824,10 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
5772
5824
|
|
|
5773
5825
|
if (!autocapture.enabledForProject(instance.get_config('token'), num_buckets, num_enabled_buckets)) {
|
|
5774
5826
|
instance['__autocapture_enabled'] = false;
|
|
5775
|
-
|
|
5827
|
+
logger.log('Not in active bucket: disabling Automatic Event Collection.');
|
|
5776
5828
|
} else if (!autocapture.isBrowserSupported()) {
|
|
5777
5829
|
instance['__autocapture_enabled'] = false;
|
|
5778
|
-
|
|
5830
|
+
logger.log('Disabling Automatic Event Collection because this browser is not supported');
|
|
5779
5831
|
} else {
|
|
5780
5832
|
autocapture.init(instance);
|
|
5781
5833
|
}
|
|
@@ -5817,12 +5869,12 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
5817
5869
|
|
|
5818
5870
|
PostHogLib.prototype.init = function (token, config, name) {
|
|
5819
5871
|
if (_.isUndefined(name)) {
|
|
5820
|
-
console
|
|
5872
|
+
console.error('You must name your new library: init(token, config, name)');
|
|
5821
5873
|
return;
|
|
5822
5874
|
}
|
|
5823
5875
|
|
|
5824
5876
|
if (name === PRIMARY_INSTANCE_NAME) {
|
|
5825
|
-
console
|
|
5877
|
+
console.error('You must initialize the main posthog object right after you include the PostHog js snippet');
|
|
5826
5878
|
return;
|
|
5827
5879
|
}
|
|
5828
5880
|
|
|
@@ -5889,7 +5941,7 @@ PostHogLib.prototype._loaded = function () {
|
|
|
5889
5941
|
try {
|
|
5890
5942
|
this.get_config('loaded')(this);
|
|
5891
5943
|
} catch (err) {
|
|
5892
|
-
console
|
|
5944
|
+
console.error('`loaded` function failed', err);
|
|
5893
5945
|
}
|
|
5894
5946
|
|
|
5895
5947
|
this._start_queue_if_opted_in(); // this happens after so a user can call identify in
|
|
@@ -6052,7 +6104,7 @@ PostHogLib.prototype._send_request = function (url, data, options, callback) {
|
|
|
6052
6104
|
})));
|
|
6053
6105
|
} catch (e) {
|
|
6054
6106
|
if (this.get_config('debug')) {
|
|
6055
|
-
console
|
|
6107
|
+
console.error(e);
|
|
6056
6108
|
}
|
|
6057
6109
|
}
|
|
6058
6110
|
} else if (USE_XHR) {
|
|
@@ -6069,7 +6121,7 @@ PostHogLib.prototype._send_request = function (url, data, options, callback) {
|
|
|
6069
6121
|
onXHRError: this.get_config('on_xhr_error')
|
|
6070
6122
|
});
|
|
6071
6123
|
} catch (e) {
|
|
6072
|
-
console
|
|
6124
|
+
console.error(e);
|
|
6073
6125
|
}
|
|
6074
6126
|
} else {
|
|
6075
6127
|
var script = document$1.createElement('script');
|
|
@@ -6195,7 +6247,7 @@ PostHogLib.prototype.capture = addOptOutCheckPostHogLib(function (event_name, pr
|
|
|
6195
6247
|
}
|
|
6196
6248
|
|
|
6197
6249
|
if (_.isUndefined(event_name) || typeof event_name !== 'string') {
|
|
6198
|
-
console
|
|
6250
|
+
console.error('No event name provided to posthog.capture');
|
|
6199
6251
|
return;
|
|
6200
6252
|
}
|
|
6201
6253
|
|
|
@@ -6227,7 +6279,7 @@ PostHogLib.prototype.capture = addOptOutCheckPostHogLib(function (event_name, pr
|
|
|
6227
6279
|
data = _.copyAndTruncateStrings(data, options._noTruncate ? null : this.get_config('properties_string_max_length'));
|
|
6228
6280
|
|
|
6229
6281
|
if (this.get_config('debug')) {
|
|
6230
|
-
|
|
6282
|
+
logger.log('PostHog.js send', data);
|
|
6231
6283
|
}
|
|
6232
6284
|
|
|
6233
6285
|
var jsonData = JSON.stringify(data);
|
|
@@ -6261,7 +6313,8 @@ PostHogLib.prototype._invokeCaptureHooks = function (eventName, eventData) {
|
|
|
6261
6313
|
|
|
6262
6314
|
PostHogLib.prototype._calculate_event_properties = function (event_name, event_properties, start_timestamp) {
|
|
6263
6315
|
// set defaults
|
|
6264
|
-
var properties =
|
|
6316
|
+
var properties = _objectSpread2({}, event_properties);
|
|
6317
|
+
|
|
6265
6318
|
properties['token'] = this.get_config('token');
|
|
6266
6319
|
|
|
6267
6320
|
if (event_name === '$snapshot') {
|
|
@@ -6302,7 +6355,7 @@ PostHogLib.prototype._calculate_event_properties = function (event_name, event_p
|
|
|
6302
6355
|
delete properties[blacklisted_prop];
|
|
6303
6356
|
});
|
|
6304
6357
|
} else {
|
|
6305
|
-
console
|
|
6358
|
+
console.error('Invalid value for property_blacklist config: ' + property_blacklist);
|
|
6306
6359
|
}
|
|
6307
6360
|
|
|
6308
6361
|
var sanitize_properties = this.get_config('sanitize_properties');
|
|
@@ -6471,7 +6524,7 @@ PostHogLib.prototype.onFeatureFlags = function (callback) {
|
|
|
6471
6524
|
PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
|
|
6472
6525
|
//if the new_distinct_id has not been set ignore the identify event
|
|
6473
6526
|
if (!new_distinct_id) {
|
|
6474
|
-
console
|
|
6527
|
+
console.error('Unique user id has not been set in posthog.identify');
|
|
6475
6528
|
return;
|
|
6476
6529
|
}
|
|
6477
6530
|
|
|
@@ -6541,7 +6594,7 @@ PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet,
|
|
|
6541
6594
|
|
|
6542
6595
|
PostHogLib.prototype.group = function (groupType, groupKey, groupPropertiesToSet) {
|
|
6543
6596
|
if (!groupType || !groupKey) {
|
|
6544
|
-
console
|
|
6597
|
+
console.error('posthog.group requires a group type and group key');
|
|
6545
6598
|
return;
|
|
6546
6599
|
}
|
|
6547
6600
|
|
|
@@ -6635,7 +6688,7 @@ PostHogLib.prototype.alias = function (alias, original) {
|
|
|
6635
6688
|
// posthog.people.identify() call made for this user. It is VERY BAD to make an alias with
|
|
6636
6689
|
// this ID, as it will duplicate users.
|
|
6637
6690
|
if (alias === this.get_property(PEOPLE_DISTINCT_ID_KEY)) {
|
|
6638
|
-
console
|
|
6691
|
+
console.critical('Attempting to create alias for existing People user - aborting.');
|
|
6639
6692
|
return -2;
|
|
6640
6693
|
}
|
|
6641
6694
|
|
|
@@ -6656,7 +6709,7 @@ PostHogLib.prototype.alias = function (alias, original) {
|
|
|
6656
6709
|
_this.identify(alias);
|
|
6657
6710
|
});
|
|
6658
6711
|
} else {
|
|
6659
|
-
console
|
|
6712
|
+
console.error('alias matches current distinct_id - skipping api call.');
|
|
6660
6713
|
this.identify(alias);
|
|
6661
6714
|
return -1;
|
|
6662
6715
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.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",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"fast-check": "^2.17.0",
|
|
51
51
|
"given2": "^2.1.7",
|
|
52
52
|
"husky": "^4.2.5",
|
|
53
|
-
"jest": "^
|
|
53
|
+
"jest": "^27.5.1",
|
|
54
54
|
"jsdom": "16.2.2",
|
|
55
55
|
"jsdom-global": "3.0.2",
|
|
56
56
|
"lint-staged": "^10.2.11",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"posthog-js": "link:.",
|
|
61
61
|
"prettier": "^2.0.5",
|
|
62
62
|
"rollup": "^2.18.2",
|
|
63
|
-
"rrweb": "^1.
|
|
63
|
+
"rrweb": "^1.1.2",
|
|
64
64
|
"sinon": "9.0.2",
|
|
65
65
|
"testcafe": "^1.17.1",
|
|
66
66
|
"testcafe-browser-provider-browserstack": "^1.13.2-alpha.1",
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"setupFilesAfterEnv": [
|
|
93
93
|
"given2/setup"
|
|
94
94
|
],
|
|
95
|
-
"clearMocks": true
|
|
95
|
+
"clearMocks": true,
|
|
96
|
+
"testEnvironment": "jsdom"
|
|
96
97
|
}
|
|
97
98
|
}
|