posthog-js 1.32.4 → 1.34.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 +22 -0
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +129 -47
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +33 -10
- package/dist/module.js +129 -47
- package/dist/module.js.map +1 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
package/dist/es.js
CHANGED
|
@@ -120,6 +120,42 @@ function _isNativeReflectConstruct() {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
124
|
+
if (source == null) return {};
|
|
125
|
+
var target = {};
|
|
126
|
+
var sourceKeys = Object.keys(source);
|
|
127
|
+
var key, i;
|
|
128
|
+
|
|
129
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
130
|
+
key = sourceKeys[i];
|
|
131
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
132
|
+
target[key] = source[key];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return target;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function _objectWithoutProperties(source, excluded) {
|
|
139
|
+
if (source == null) return {};
|
|
140
|
+
|
|
141
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
142
|
+
|
|
143
|
+
var key, i;
|
|
144
|
+
|
|
145
|
+
if (Object.getOwnPropertySymbols) {
|
|
146
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
147
|
+
|
|
148
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
149
|
+
key = sourceSymbolKeys[i];
|
|
150
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
151
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
152
|
+
target[key] = source[key];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return target;
|
|
157
|
+
}
|
|
158
|
+
|
|
123
159
|
function _assertThisInitialized(self) {
|
|
124
160
|
if (self === void 0) {
|
|
125
161
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -881,7 +917,7 @@ var LZString = {
|
|
|
881
917
|
}
|
|
882
918
|
};
|
|
883
919
|
|
|
884
|
-
var version = "1.
|
|
920
|
+
var version = "1.34.0";
|
|
885
921
|
|
|
886
922
|
// e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
|
|
887
923
|
|
|
@@ -1641,6 +1677,11 @@ var _info = {
|
|
|
1641
1677
|
|
|
1642
1678
|
return parseFloat(matches[matches.length - 2]);
|
|
1643
1679
|
},
|
|
1680
|
+
browserLanguage: function browserLanguage() {
|
|
1681
|
+
return navigator.language || // Any modern browser
|
|
1682
|
+
navigator.userLanguage // IE11
|
|
1683
|
+
;
|
|
1684
|
+
},
|
|
1644
1685
|
os: function os() {
|
|
1645
1686
|
var a = userAgent;
|
|
1646
1687
|
|
|
@@ -1716,6 +1757,7 @@ var _info = {
|
|
|
1716
1757
|
$host: window.location.host,
|
|
1717
1758
|
$pathname: window.location.pathname,
|
|
1718
1759
|
$browser_version: _info.browserVersion(userAgent, navigator.vendor, window.opera),
|
|
1760
|
+
$browser_language: _info.browserLanguage(),
|
|
1719
1761
|
$screen_height: window.screen.height,
|
|
1720
1762
|
$screen_width: window.screen.width,
|
|
1721
1763
|
$viewport_height: window.innerHeight,
|
|
@@ -4097,6 +4139,9 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4097
4139
|
return Decide;
|
|
4098
4140
|
}();
|
|
4099
4141
|
|
|
4142
|
+
var POSTHOG_MANAGED_HOSTS = ['https://app.posthog.com', 'https://eu.posthog.com'];
|
|
4143
|
+
|
|
4144
|
+
var _excluded = ["source"];
|
|
4100
4145
|
var Toolbar = /*#__PURE__*/function () {
|
|
4101
4146
|
function Toolbar(instance) {
|
|
4102
4147
|
_classCallCheck(this, Toolbar);
|
|
@@ -4107,25 +4152,25 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4107
4152
|
_createClass(Toolbar, [{
|
|
4108
4153
|
key: "afterDecideResponse",
|
|
4109
4154
|
value: function afterDecideResponse(response) {
|
|
4110
|
-
var
|
|
4155
|
+
var toolbarParams = response['toolbarParams'] || response['editorParams'] || (response['toolbarVersion'] ? {
|
|
4111
4156
|
toolbarVersion: response['toolbarVersion']
|
|
4112
4157
|
} : {});
|
|
4113
4158
|
|
|
4114
|
-
if (response['isAuthenticated'] &&
|
|
4115
|
-
this.
|
|
4159
|
+
if (response['isAuthenticated'] && toolbarParams['toolbarVersion'] && toolbarParams['toolbarVersion'].indexOf('toolbar') === 0) {
|
|
4160
|
+
this.loadToolbar(_objectSpread2(_objectSpread2({}, toolbarParams), {}, {
|
|
4116
4161
|
apiURL: this.instance.get_config('api_host')
|
|
4117
4162
|
}));
|
|
4118
4163
|
}
|
|
4119
4164
|
}
|
|
4120
4165
|
/**
|
|
4121
|
-
* To load the
|
|
4122
|
-
* 1. In the URL hash params
|
|
4123
|
-
* 2. From session storage under the key `
|
|
4166
|
+
* To load the toolbar, we need an access token and other state. That state comes from one of three places:
|
|
4167
|
+
* 1. In the URL hash params
|
|
4168
|
+
* 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page
|
|
4124
4169
|
*/
|
|
4125
4170
|
|
|
4126
4171
|
}, {
|
|
4127
|
-
key: "
|
|
4128
|
-
value: function
|
|
4172
|
+
key: "maybeLoadToolbar",
|
|
4173
|
+
value: function maybeLoadToolbar() {
|
|
4129
4174
|
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4130
4175
|
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4131
4176
|
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
@@ -4147,16 +4192,15 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4147
4192
|
var stateHash = _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state');
|
|
4148
4193
|
|
|
4149
4194
|
var state = stateHash ? JSON.parse(decodeURIComponent(stateHash)) : null;
|
|
4150
|
-
var parseFromUrl = state &&
|
|
4151
|
-
var
|
|
4195
|
+
var parseFromUrl = state && state['action'] === 'ph_authorize';
|
|
4196
|
+
var toolbarParams;
|
|
4152
4197
|
|
|
4153
4198
|
if (parseFromUrl) {
|
|
4154
|
-
// happens if they are initializing the
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
if (editorParams && Object.keys(editorParams).length > 0) {
|
|
4158
|
-
localStorage.setItem('_postHogEditorParams', JSON.stringify(editorParams));
|
|
4199
|
+
// happens if they are initializing the toolbar using an old snippet
|
|
4200
|
+
toolbarParams = state;
|
|
4201
|
+
toolbarParams.source = 'url';
|
|
4159
4202
|
|
|
4203
|
+
if (toolbarParams && Object.keys(toolbarParams).length > 0) {
|
|
4160
4204
|
if (state['desiredHash']) {
|
|
4161
4205
|
// hash that was in the url before the redirect
|
|
4162
4206
|
location.hash = state['desiredHash'];
|
|
@@ -4168,19 +4212,19 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4168
4212
|
}
|
|
4169
4213
|
} else {
|
|
4170
4214
|
// get credentials from localStorage from a previous initialzation
|
|
4171
|
-
|
|
4215
|
+
toolbarParams = JSON.parse(localStorage.getItem('_postHogToolbarParams') || '{}');
|
|
4216
|
+
toolbarParams.source = 'localstorage'; // delete "add-action" or other intent from toolbarParams, otherwise we'll have the same intent
|
|
4172
4217
|
// every time we open the page (e.g. you just visiting your own site an hour later)
|
|
4173
4218
|
|
|
4174
|
-
delete
|
|
4219
|
+
delete toolbarParams.userIntent;
|
|
4175
4220
|
}
|
|
4176
4221
|
|
|
4177
|
-
if (!
|
|
4178
|
-
|
|
4222
|
+
if (!toolbarParams.apiURL) {
|
|
4223
|
+
toolbarParams.apiURL = this.instance.get_config('api_host');
|
|
4179
4224
|
}
|
|
4180
4225
|
|
|
4181
|
-
if (
|
|
4182
|
-
this.
|
|
4183
|
-
|
|
4226
|
+
if (toolbarParams['token'] && this.instance.get_config('token') === toolbarParams['token']) {
|
|
4227
|
+
this.loadToolbar(toolbarParams);
|
|
4184
4228
|
return true;
|
|
4185
4229
|
} else {
|
|
4186
4230
|
return false;
|
|
@@ -4190,33 +4234,61 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4190
4234
|
}
|
|
4191
4235
|
}
|
|
4192
4236
|
}, {
|
|
4193
|
-
key: "
|
|
4194
|
-
value: function
|
|
4237
|
+
key: "loadToolbar",
|
|
4238
|
+
value: function loadToolbar(params) {
|
|
4195
4239
|
var _this = this;
|
|
4196
4240
|
|
|
4197
|
-
if (
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
});
|
|
4241
|
+
if (window['_postHogToolbarLoaded']) {
|
|
4242
|
+
return false;
|
|
4243
|
+
} // only load the toolbar once, even if there are multiple instances of PostHogLib
|
|
4244
|
+
window['_postHogToolbarLoaded'] = true;
|
|
4245
|
+
var host = (params === null || params === void 0 ? void 0 : params['jsURL']) || (params === null || params === void 0 ? void 0 : params['apiURL']) || this.instance.get_config('api_host');
|
|
4246
|
+
var toolbarUrl = "".concat(host).concat(host.endsWith('/') ? '' : '/', "static/toolbar.js?_ts=").concat(new Date().getTime());
|
|
4247
|
+
var disableToolbarMetrics = !POSTHOG_MANAGED_HOSTS.includes(this.instance.get_config('api_host')) && this.instance.get_config('advanced_disable_toolbar_metrics');
|
|
4248
|
+
|
|
4249
|
+
var toolbarParams = _objectSpread2(_objectSpread2({
|
|
4250
|
+
apiURL: host,
|
|
4251
|
+
// defaults to api_host from the instance config if nothing else set
|
|
4252
|
+
jsURL: host,
|
|
4253
|
+
// defaults to api_host from the instance config if nothing else set
|
|
4254
|
+
token: this.instance.get_config('token')
|
|
4255
|
+
}, params), disableToolbarMetrics ? {
|
|
4256
|
+
instrument: false
|
|
4257
|
+
} : {});
|
|
4215
4258
|
|
|
4216
|
-
|
|
4217
|
-
|
|
4259
|
+
toolbarParams.source;
|
|
4260
|
+
var paramsToPersist = _objectWithoutProperties(toolbarParams, _excluded); // eslint-disable-line
|
|
4218
4261
|
|
|
4219
|
-
|
|
4262
|
+
|
|
4263
|
+
window.localStorage.setItem('_postHogToolbarParams', JSON.stringify(paramsToPersist));
|
|
4264
|
+
loadScript(toolbarUrl, function () {
|
|
4265
|
+
(window['ph_load_toolbar'] || window['ph_load_editor'])(toolbarParams, _this.instance);
|
|
4266
|
+
}); // Turbolinks doesn't fire an onload event but does replace the entire page, including the toolbar
|
|
4267
|
+
|
|
4268
|
+
_register_event(window, 'turbolinks:load', function () {
|
|
4269
|
+
window['_postHogToolbarLoaded'] = false;
|
|
4270
|
+
|
|
4271
|
+
_this.loadToolbar(toolbarParams);
|
|
4272
|
+
});
|
|
4273
|
+
|
|
4274
|
+
return true;
|
|
4275
|
+
}
|
|
4276
|
+
/** @deprecated Use "loadToolbar" instead. */
|
|
4277
|
+
|
|
4278
|
+
}, {
|
|
4279
|
+
key: "_loadEditor",
|
|
4280
|
+
value: function _loadEditor(params) {
|
|
4281
|
+
return this.loadToolbar(params);
|
|
4282
|
+
}
|
|
4283
|
+
/** @deprecated Use "maybeLoadToolbar" instead. */
|
|
4284
|
+
|
|
4285
|
+
}, {
|
|
4286
|
+
key: "maybeLoadEditor",
|
|
4287
|
+
value: function maybeLoadEditor() {
|
|
4288
|
+
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4289
|
+
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4290
|
+
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
4291
|
+
return this.maybeLoadToolbar(location, localStorage, history);
|
|
4220
4292
|
}
|
|
4221
4293
|
}]);
|
|
4222
4294
|
|
|
@@ -6079,7 +6151,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
6079
6151
|
|
|
6080
6152
|
instance._init(token, config, name);
|
|
6081
6153
|
|
|
6082
|
-
instance.toolbar.
|
|
6154
|
+
instance.toolbar.maybeLoadToolbar();
|
|
6083
6155
|
instance.sessionRecording = new SessionRecording(instance);
|
|
6084
6156
|
instance.sessionRecording.startRecordingIfEnabled();
|
|
6085
6157
|
instance.__autocapture_enabled = instance.get_config('autocapture');
|
|
@@ -7290,6 +7362,16 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
7290
7362
|
|
|
7291
7363
|
return !!((_this$sessionRecordin = this.sessionRecording) !== null && _this$sessionRecordin !== void 0 && _this$sessionRecordin.started());
|
|
7292
7364
|
}
|
|
7365
|
+
/**
|
|
7366
|
+
* returns a boolean indicating whether the toolbar loaded
|
|
7367
|
+
* @param toolbarParams
|
|
7368
|
+
*/
|
|
7369
|
+
|
|
7370
|
+
}, {
|
|
7371
|
+
key: "loadToolbar",
|
|
7372
|
+
value: function loadToolbar(params) {
|
|
7373
|
+
return this.toolbar.loadToolbar(params);
|
|
7374
|
+
}
|
|
7293
7375
|
/**
|
|
7294
7376
|
* returns the current config object for the library.
|
|
7295
7377
|
*/
|