posthog-js 1.34.0 → 1.35.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 +8 -0
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +102 -14
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +4 -1
- package/dist/module.js +102 -14
- package/dist/module.js.map +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/dist/es.js
CHANGED
|
@@ -917,7 +917,7 @@ var LZString = {
|
|
|
917
917
|
}
|
|
918
918
|
};
|
|
919
919
|
|
|
920
|
-
var version = "1.
|
|
920
|
+
var version = "1.35.0";
|
|
921
921
|
|
|
922
922
|
// e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
|
|
923
923
|
|
|
@@ -4075,8 +4075,9 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4075
4075
|
(_this$instance$sessio = this.instance.sessionRecording) === null || _this$instance$sessio === void 0 ? void 0 : _this$instance$sessio.afterDecideResponse(response);
|
|
4076
4076
|
autocapture.afterDecideResponse(response, this.instance);
|
|
4077
4077
|
this.instance.featureFlags.receivedFeatureFlags(response);
|
|
4078
|
+
this.instance['compression'] = {};
|
|
4078
4079
|
|
|
4079
|
-
if (response['supportedCompression']) {
|
|
4080
|
+
if (response['supportedCompression'] && !this.instance.get_config('disable_compression')) {
|
|
4080
4081
|
var compression = {};
|
|
4081
4082
|
|
|
4082
4083
|
var _iterator = _createForOfIteratorHelper(response['supportedCompression']),
|
|
@@ -4094,8 +4095,6 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4094
4095
|
}
|
|
4095
4096
|
|
|
4096
4097
|
this.instance['compression'] = compression;
|
|
4097
|
-
} else {
|
|
4098
|
-
this.instance['compression'] = {};
|
|
4099
4098
|
}
|
|
4100
4099
|
|
|
4101
4100
|
if (response['siteApps']) {
|
|
@@ -6006,6 +6005,70 @@ var SentryIntegration = /*#__PURE__*/_createClass(function SentryIntegration(_po
|
|
|
6006
6005
|
};
|
|
6007
6006
|
});
|
|
6008
6007
|
|
|
6008
|
+
/**
|
|
6009
|
+
* Extend Segment with extra PostHog JS functionality. Required for things like Recordings and feature flags to work correctly.
|
|
6010
|
+
*
|
|
6011
|
+
* ### Usage
|
|
6012
|
+
*
|
|
6013
|
+
* ```js
|
|
6014
|
+
* // After your standard segment anyalytics install
|
|
6015
|
+
* analytics.load("GOEDfA21zZTtR7clsBuDvmBKAtAdZ6Np");
|
|
6016
|
+
*
|
|
6017
|
+
* analytics.ready(() => {
|
|
6018
|
+
* posthog.init('<posthog-api-key>', {
|
|
6019
|
+
* capture_pageview: false,
|
|
6020
|
+
* segment: window.analytics, // NOTE: Be sure to use window.analytics here!
|
|
6021
|
+
* });
|
|
6022
|
+
* window.analytics.page();
|
|
6023
|
+
* })
|
|
6024
|
+
* ```
|
|
6025
|
+
*/
|
|
6026
|
+
// Loosely based on https://github.com/segmentio/analytics-next/blob/master/packages/core/src/plugins/index.ts
|
|
6027
|
+
var createSegmentIntegration = function createSegmentIntegration(posthog) {
|
|
6028
|
+
var enrichEvent = function enrichEvent(ctx, eventName) {
|
|
6029
|
+
if (!ctx.event.userId && ctx.event.anonymousId !== posthog.get_distinct_id()) {
|
|
6030
|
+
// This is our only way of detecting that segment's analytics.reset() has been called so we also call it
|
|
6031
|
+
posthog.reset();
|
|
6032
|
+
}
|
|
6033
|
+
|
|
6034
|
+
if (ctx.event.userId && ctx.event.userId !== posthog.get_distinct_id()) {
|
|
6035
|
+
posthog.register({
|
|
6036
|
+
distinct_id: ctx.event.userId
|
|
6037
|
+
});
|
|
6038
|
+
posthog.reloadFeatureFlags();
|
|
6039
|
+
}
|
|
6040
|
+
|
|
6041
|
+
var additionalProperties = posthog._calculate_event_properties(eventName, ctx.event.properties);
|
|
6042
|
+
|
|
6043
|
+
ctx.event.properties = Object.assign({}, additionalProperties, ctx.event.properties);
|
|
6044
|
+
return ctx;
|
|
6045
|
+
};
|
|
6046
|
+
|
|
6047
|
+
return {
|
|
6048
|
+
name: 'PostHog JS',
|
|
6049
|
+
type: 'enrichment',
|
|
6050
|
+
version: '1.0.0',
|
|
6051
|
+
isLoaded: function isLoaded() {
|
|
6052
|
+
return true;
|
|
6053
|
+
},
|
|
6054
|
+
load: function load() {
|
|
6055
|
+
return Promise.resolve();
|
|
6056
|
+
},
|
|
6057
|
+
track: function track(ctx) {
|
|
6058
|
+
return enrichEvent(ctx, ctx.event.event);
|
|
6059
|
+
},
|
|
6060
|
+
page: function page(ctx) {
|
|
6061
|
+
return enrichEvent(ctx, '$pageview');
|
|
6062
|
+
},
|
|
6063
|
+
identify: function identify(ctx) {
|
|
6064
|
+
return enrichEvent(ctx, '$identify');
|
|
6065
|
+
},
|
|
6066
|
+
screen: function screen(ctx) {
|
|
6067
|
+
return enrichEvent(ctx, '$screen');
|
|
6068
|
+
}
|
|
6069
|
+
};
|
|
6070
|
+
};
|
|
6071
|
+
|
|
6009
6072
|
/*
|
|
6010
6073
|
SIMPLE STYLE GUIDE:
|
|
6011
6074
|
|
|
@@ -6118,7 +6181,8 @@ var defaultConfig = function defaultConfig() {
|
|
|
6118
6181
|
_capture_performance: false,
|
|
6119
6182
|
name: 'posthog',
|
|
6120
6183
|
callback_fn: 'posthog._jsc',
|
|
6121
|
-
bootstrap: {}
|
|
6184
|
+
bootstrap: {},
|
|
6185
|
+
disable_compression: false
|
|
6122
6186
|
};
|
|
6123
6187
|
};
|
|
6124
6188
|
/**
|
|
@@ -6194,12 +6258,19 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
6194
6258
|
|
|
6195
6259
|
var PostHog = /*#__PURE__*/function () {
|
|
6196
6260
|
function PostHog() {
|
|
6261
|
+
var _this = this;
|
|
6262
|
+
|
|
6197
6263
|
_classCallCheck(this, PostHog);
|
|
6198
6264
|
|
|
6199
6265
|
this.config = defaultConfig();
|
|
6200
6266
|
this.compression = {};
|
|
6201
6267
|
this.decideEndpointWasHit = false;
|
|
6202
6268
|
this.SentryIntegration = SentryIntegration;
|
|
6269
|
+
|
|
6270
|
+
this.segmentIntegration = function () {
|
|
6271
|
+
return createSegmentIntegration(_this);
|
|
6272
|
+
};
|
|
6273
|
+
|
|
6203
6274
|
this.__captureHooks = [];
|
|
6204
6275
|
this.__request_queue = [];
|
|
6205
6276
|
this.__loaded = false;
|
|
@@ -6293,6 +6364,22 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6293
6364
|
|
|
6294
6365
|
this._gdpr_init();
|
|
6295
6366
|
|
|
6367
|
+
if (config.segment) {
|
|
6368
|
+
// Use segments anonymousId instead
|
|
6369
|
+
this.config.get_device_id = function () {
|
|
6370
|
+
return config.segment.user().anonymousId();
|
|
6371
|
+
}; // If a segment user ID exists, set it as the distinct_id
|
|
6372
|
+
|
|
6373
|
+
|
|
6374
|
+
if (config.segment.user().id()) {
|
|
6375
|
+
this.register({
|
|
6376
|
+
distinct_id: config.segment.user().id()
|
|
6377
|
+
});
|
|
6378
|
+
}
|
|
6379
|
+
|
|
6380
|
+
config.segment.register(this.segmentIntegration());
|
|
6381
|
+
}
|
|
6382
|
+
|
|
6296
6383
|
if (((_config$bootstrap = config.bootstrap) === null || _config$bootstrap === void 0 ? void 0 : _config$bootstrap.distinctID) !== undefined) {
|
|
6297
6384
|
var _config$bootstrap2;
|
|
6298
6385
|
|
|
@@ -6383,11 +6470,11 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6383
6470
|
}, {
|
|
6384
6471
|
key: "_dom_loaded",
|
|
6385
6472
|
value: function _dom_loaded() {
|
|
6386
|
-
var
|
|
6473
|
+
var _this2 = this;
|
|
6387
6474
|
|
|
6388
6475
|
if (!this.has_opted_out_capturing()) {
|
|
6389
6476
|
_eachArray(this.__request_queue, function (item) {
|
|
6390
|
-
|
|
6477
|
+
_this2._send_request.apply(_this2, _toConsumableArray(item));
|
|
6391
6478
|
});
|
|
6392
6479
|
}
|
|
6393
6480
|
|
|
@@ -6564,7 +6651,7 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6564
6651
|
}, {
|
|
6565
6652
|
key: "_execute_array",
|
|
6566
6653
|
value: function _execute_array(array) {
|
|
6567
|
-
var
|
|
6654
|
+
var _this3 = this;
|
|
6568
6655
|
|
|
6569
6656
|
var fn_name;
|
|
6570
6657
|
var alias_calls = [];
|
|
@@ -6578,10 +6665,10 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6578
6665
|
if (_isArray(fn_name)) {
|
|
6579
6666
|
capturing_calls.push(item); // chained call e.g. posthog.get_group().set()
|
|
6580
6667
|
} else if (typeof item === 'function') {
|
|
6581
|
-
item.call(
|
|
6668
|
+
item.call(_this3);
|
|
6582
6669
|
} else if (_isArray(item) && fn_name === 'alias') {
|
|
6583
6670
|
alias_calls.push(item);
|
|
6584
|
-
} else if (_isArray(item) && fn_name.indexOf('capture') !== -1 && typeof
|
|
6671
|
+
} else if (_isArray(item) && fn_name.indexOf('capture') !== -1 && typeof _this3[fn_name] === 'function') {
|
|
6585
6672
|
capturing_calls.push(item);
|
|
6586
6673
|
} else {
|
|
6587
6674
|
other_calls.push(item);
|
|
@@ -6690,9 +6777,8 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6690
6777
|
|
|
6691
6778
|
if (_isBlockedUA(userAgent)) {
|
|
6692
6779
|
return;
|
|
6693
|
-
}
|
|
6780
|
+
} // update persistence
|
|
6694
6781
|
|
|
6695
|
-
var start_timestamp = this.persistence.remove_event_timer(event_name); // update persistence
|
|
6696
6782
|
|
|
6697
6783
|
this.persistence.update_search_keyword(document$1.referrer);
|
|
6698
6784
|
|
|
@@ -6706,7 +6792,7 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6706
6792
|
|
|
6707
6793
|
var data = {
|
|
6708
6794
|
event: event_name,
|
|
6709
|
-
properties: this._calculate_event_properties(event_name, properties || {}
|
|
6795
|
+
properties: this._calculate_event_properties(event_name, properties || {})
|
|
6710
6796
|
};
|
|
6711
6797
|
|
|
6712
6798
|
if (event_name === '$identify' && options.$set) {
|
|
@@ -6750,8 +6836,10 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
6750
6836
|
}
|
|
6751
6837
|
}, {
|
|
6752
6838
|
key: "_calculate_event_properties",
|
|
6753
|
-
value: function _calculate_event_properties(event_name, event_properties
|
|
6839
|
+
value: function _calculate_event_properties(event_name, event_properties) {
|
|
6754
6840
|
// set defaults
|
|
6841
|
+
var start_timestamp = this.persistence.remove_event_timer(event_name);
|
|
6842
|
+
|
|
6755
6843
|
var properties = _objectSpread2({}, event_properties);
|
|
6756
6844
|
|
|
6757
6845
|
properties['token'] = this.get_config('token');
|