posthog-js 1.33.0 → 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 +18 -0
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +123 -47
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +33 -10
- package/dist/module.js +123 -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
|
|
|
@@ -4103,6 +4139,9 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4103
4139
|
return Decide;
|
|
4104
4140
|
}();
|
|
4105
4141
|
|
|
4142
|
+
var POSTHOG_MANAGED_HOSTS = ['https://app.posthog.com', 'https://eu.posthog.com'];
|
|
4143
|
+
|
|
4144
|
+
var _excluded = ["source"];
|
|
4106
4145
|
var Toolbar = /*#__PURE__*/function () {
|
|
4107
4146
|
function Toolbar(instance) {
|
|
4108
4147
|
_classCallCheck(this, Toolbar);
|
|
@@ -4113,25 +4152,25 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4113
4152
|
_createClass(Toolbar, [{
|
|
4114
4153
|
key: "afterDecideResponse",
|
|
4115
4154
|
value: function afterDecideResponse(response) {
|
|
4116
|
-
var
|
|
4155
|
+
var toolbarParams = response['toolbarParams'] || response['editorParams'] || (response['toolbarVersion'] ? {
|
|
4117
4156
|
toolbarVersion: response['toolbarVersion']
|
|
4118
4157
|
} : {});
|
|
4119
4158
|
|
|
4120
|
-
if (response['isAuthenticated'] &&
|
|
4121
|
-
this.
|
|
4159
|
+
if (response['isAuthenticated'] && toolbarParams['toolbarVersion'] && toolbarParams['toolbarVersion'].indexOf('toolbar') === 0) {
|
|
4160
|
+
this.loadToolbar(_objectSpread2(_objectSpread2({}, toolbarParams), {}, {
|
|
4122
4161
|
apiURL: this.instance.get_config('api_host')
|
|
4123
4162
|
}));
|
|
4124
4163
|
}
|
|
4125
4164
|
}
|
|
4126
4165
|
/**
|
|
4127
|
-
* To load the
|
|
4128
|
-
* 1. In the URL hash params
|
|
4129
|
-
* 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
|
|
4130
4169
|
*/
|
|
4131
4170
|
|
|
4132
4171
|
}, {
|
|
4133
|
-
key: "
|
|
4134
|
-
value: function
|
|
4172
|
+
key: "maybeLoadToolbar",
|
|
4173
|
+
value: function maybeLoadToolbar() {
|
|
4135
4174
|
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4136
4175
|
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4137
4176
|
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
@@ -4153,16 +4192,15 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4153
4192
|
var stateHash = _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state');
|
|
4154
4193
|
|
|
4155
4194
|
var state = stateHash ? JSON.parse(decodeURIComponent(stateHash)) : null;
|
|
4156
|
-
var parseFromUrl = state &&
|
|
4157
|
-
var
|
|
4195
|
+
var parseFromUrl = state && state['action'] === 'ph_authorize';
|
|
4196
|
+
var toolbarParams;
|
|
4158
4197
|
|
|
4159
4198
|
if (parseFromUrl) {
|
|
4160
|
-
// happens if they are initializing the
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
if (editorParams && Object.keys(editorParams).length > 0) {
|
|
4164
|
-
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';
|
|
4165
4202
|
|
|
4203
|
+
if (toolbarParams && Object.keys(toolbarParams).length > 0) {
|
|
4166
4204
|
if (state['desiredHash']) {
|
|
4167
4205
|
// hash that was in the url before the redirect
|
|
4168
4206
|
location.hash = state['desiredHash'];
|
|
@@ -4174,19 +4212,19 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4174
4212
|
}
|
|
4175
4213
|
} else {
|
|
4176
4214
|
// get credentials from localStorage from a previous initialzation
|
|
4177
|
-
|
|
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
|
|
4178
4217
|
// every time we open the page (e.g. you just visiting your own site an hour later)
|
|
4179
4218
|
|
|
4180
|
-
delete
|
|
4219
|
+
delete toolbarParams.userIntent;
|
|
4181
4220
|
}
|
|
4182
4221
|
|
|
4183
|
-
if (!
|
|
4184
|
-
|
|
4222
|
+
if (!toolbarParams.apiURL) {
|
|
4223
|
+
toolbarParams.apiURL = this.instance.get_config('api_host');
|
|
4185
4224
|
}
|
|
4186
4225
|
|
|
4187
|
-
if (
|
|
4188
|
-
this.
|
|
4189
|
-
|
|
4226
|
+
if (toolbarParams['token'] && this.instance.get_config('token') === toolbarParams['token']) {
|
|
4227
|
+
this.loadToolbar(toolbarParams);
|
|
4190
4228
|
return true;
|
|
4191
4229
|
} else {
|
|
4192
4230
|
return false;
|
|
@@ -4196,33 +4234,61 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4196
4234
|
}
|
|
4197
4235
|
}
|
|
4198
4236
|
}, {
|
|
4199
|
-
key: "
|
|
4200
|
-
value: function
|
|
4237
|
+
key: "loadToolbar",
|
|
4238
|
+
value: function loadToolbar(params) {
|
|
4201
4239
|
var _this = this;
|
|
4202
4240
|
|
|
4203
|
-
if (
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
});
|
|
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
|
+
} : {});
|
|
4221
4258
|
|
|
4222
|
-
|
|
4223
|
-
|
|
4259
|
+
toolbarParams.source;
|
|
4260
|
+
var paramsToPersist = _objectWithoutProperties(toolbarParams, _excluded); // eslint-disable-line
|
|
4224
4261
|
|
|
4225
|
-
|
|
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);
|
|
4226
4292
|
}
|
|
4227
4293
|
}]);
|
|
4228
4294
|
|
|
@@ -6085,7 +6151,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
6085
6151
|
|
|
6086
6152
|
instance._init(token, config, name);
|
|
6087
6153
|
|
|
6088
|
-
instance.toolbar.
|
|
6154
|
+
instance.toolbar.maybeLoadToolbar();
|
|
6089
6155
|
instance.sessionRecording = new SessionRecording(instance);
|
|
6090
6156
|
instance.sessionRecording.startRecordingIfEnabled();
|
|
6091
6157
|
instance.__autocapture_enabled = instance.get_config('autocapture');
|
|
@@ -7296,6 +7362,16 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
7296
7362
|
|
|
7297
7363
|
return !!((_this$sessionRecordin = this.sessionRecording) !== null && _this$sessionRecordin !== void 0 && _this$sessionRecordin.started());
|
|
7298
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
|
+
}
|
|
7299
7375
|
/**
|
|
7300
7376
|
* returns the current config object for the library.
|
|
7301
7377
|
*/
|