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/module.d.ts
CHANGED
|
@@ -275,8 +275,9 @@ interface DecideResponse {
|
|
|
275
275
|
endpoint?: string;
|
|
276
276
|
consoleLogRecordingEnabled?: boolean;
|
|
277
277
|
};
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
toolbarParams: ToolbarParams;
|
|
279
|
+
editorParams?: ToolbarParams; /** @deprecated, renamed to toolbarParams, still present on older API responses */
|
|
280
|
+
toolbarVersion: 'toolbar'; /** @deprecated, moved to toolbarParams */
|
|
280
281
|
isAuthenticated: boolean;
|
|
281
282
|
siteApps: {
|
|
282
283
|
id: number;
|
|
@@ -316,10 +317,23 @@ interface PersistentStore {
|
|
|
316
317
|
}
|
|
317
318
|
declare type Breaker = {};
|
|
318
319
|
declare type EventHandler = (event: Event) => boolean | void;
|
|
319
|
-
|
|
320
|
-
|
|
320
|
+
declare type ToolbarUserIntent = 'add-action' | 'edit-action';
|
|
321
|
+
declare type ToolbarSource = 'url' | 'localstorage';
|
|
322
|
+
declare type ToolbarVersion = 'toolbar';
|
|
323
|
+
interface ToolbarParams {
|
|
321
324
|
apiURL?: string;
|
|
322
|
-
|
|
325
|
+
jsURL?: string;
|
|
326
|
+
token?: string; /** public posthog-js token */
|
|
327
|
+
temporaryToken?: string; /** private temporary user token */
|
|
328
|
+
actionId?: number;
|
|
329
|
+
userIntent?: ToolbarUserIntent;
|
|
330
|
+
source?: ToolbarSource;
|
|
331
|
+
toolbarVersion?: ToolbarVersion;
|
|
332
|
+
instrument?: boolean;
|
|
333
|
+
distinctId?: string;
|
|
334
|
+
userEmail?: string;
|
|
335
|
+
dataAttributes?: string[];
|
|
336
|
+
featureFlags?: Record<string, string | boolean>;
|
|
323
337
|
}
|
|
324
338
|
interface PostData {
|
|
325
339
|
buffer?: BlobPart;
|
|
@@ -801,12 +815,16 @@ declare class Toolbar {
|
|
|
801
815
|
constructor(instance: PostHog);
|
|
802
816
|
afterDecideResponse(response: DecideResponse): void;
|
|
803
817
|
/**
|
|
804
|
-
* To load the
|
|
805
|
-
* 1. In the URL hash params
|
|
806
|
-
* 2. From session storage under the key `
|
|
818
|
+
* To load the toolbar, we need an access token and other state. That state comes from one of three places:
|
|
819
|
+
* 1. In the URL hash params
|
|
820
|
+
* 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page
|
|
807
821
|
*/
|
|
822
|
+
maybeLoadToolbar(location?: Location, localStorage?: Storage | undefined, history?: History): boolean;
|
|
823
|
+
loadToolbar(params?: ToolbarParams): boolean;
|
|
824
|
+
/** @deprecated Use "loadToolbar" instead. */
|
|
825
|
+
_loadEditor(params: ToolbarParams): boolean;
|
|
826
|
+
/** @deprecated Use "maybeLoadToolbar" instead. */
|
|
808
827
|
maybeLoadEditor(location?: Location, localStorage?: Storage | undefined, history?: History): boolean;
|
|
809
|
-
_loadEditor(editorParams: EditorParams): boolean;
|
|
810
828
|
}
|
|
811
829
|
|
|
812
830
|
declare class RequestQueue extends RequestQueueScaffold {
|
|
@@ -1264,6 +1282,11 @@ declare class PostHog {
|
|
|
1264
1282
|
* is currently running
|
|
1265
1283
|
*/
|
|
1266
1284
|
sessionRecordingStarted(): boolean;
|
|
1285
|
+
/**
|
|
1286
|
+
* returns a boolean indicating whether the toolbar loaded
|
|
1287
|
+
* @param toolbarParams
|
|
1288
|
+
*/
|
|
1289
|
+
loadToolbar(params: ToolbarParams): boolean;
|
|
1267
1290
|
/**
|
|
1268
1291
|
* returns the current config object for the library.
|
|
1269
1292
|
*/
|
|
@@ -1408,4 +1431,4 @@ declare class PostHog {
|
|
|
1408
1431
|
|
|
1409
1432
|
declare const posthog: PostHog;
|
|
1410
1433
|
|
|
1411
|
-
export { AutoCaptureCustomProperty, Breaker, CaptureCallback, CaptureOptions, CaptureResult, Compression, CompressionData, DecideResponse,
|
|
1434
|
+
export { AutoCaptureCustomProperty, Breaker, CaptureCallback, CaptureOptions, CaptureResult, Compression, CompressionData, DecideResponse, EventHandler, FeatureFlagsCallback, GDPROptions, JSC, OptInOutCapturingOptions, PersistentStore, PostData, PostHog, PostHogConfig, Properties, Property, QueuedRequestData, RequestCallback, RetryQueueElement, SessionRecordingOptions, SnippetArrayItem, ToolbarParams, ToolbarSource, ToolbarUserIntent, ToolbarVersion, XHROptions, XHRParams, posthog as default, isFeatureEnabledOptions, posthog };
|
package/dist/module.js
CHANGED
|
@@ -124,6 +124,42 @@ function _isNativeReflectConstruct() {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
128
|
+
if (source == null) return {};
|
|
129
|
+
var target = {};
|
|
130
|
+
var sourceKeys = Object.keys(source);
|
|
131
|
+
var key, i;
|
|
132
|
+
|
|
133
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
134
|
+
key = sourceKeys[i];
|
|
135
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
136
|
+
target[key] = source[key];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return target;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function _objectWithoutProperties(source, excluded) {
|
|
143
|
+
if (source == null) return {};
|
|
144
|
+
|
|
145
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
146
|
+
|
|
147
|
+
var key, i;
|
|
148
|
+
|
|
149
|
+
if (Object.getOwnPropertySymbols) {
|
|
150
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
151
|
+
|
|
152
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
153
|
+
key = sourceSymbolKeys[i];
|
|
154
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
155
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
156
|
+
target[key] = source[key];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return target;
|
|
161
|
+
}
|
|
162
|
+
|
|
127
163
|
function _assertThisInitialized(self) {
|
|
128
164
|
if (self === void 0) {
|
|
129
165
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -885,7 +921,7 @@ var LZString = {
|
|
|
885
921
|
}
|
|
886
922
|
};
|
|
887
923
|
|
|
888
|
-
var version = "1.
|
|
924
|
+
var version = "1.34.0";
|
|
889
925
|
|
|
890
926
|
// e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
|
|
891
927
|
|
|
@@ -4107,6 +4143,9 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4107
4143
|
return Decide;
|
|
4108
4144
|
}();
|
|
4109
4145
|
|
|
4146
|
+
var POSTHOG_MANAGED_HOSTS = ['https://app.posthog.com', 'https://eu.posthog.com'];
|
|
4147
|
+
|
|
4148
|
+
var _excluded = ["source"];
|
|
4110
4149
|
var Toolbar = /*#__PURE__*/function () {
|
|
4111
4150
|
function Toolbar(instance) {
|
|
4112
4151
|
_classCallCheck(this, Toolbar);
|
|
@@ -4117,25 +4156,25 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4117
4156
|
_createClass(Toolbar, [{
|
|
4118
4157
|
key: "afterDecideResponse",
|
|
4119
4158
|
value: function afterDecideResponse(response) {
|
|
4120
|
-
var
|
|
4159
|
+
var toolbarParams = response['toolbarParams'] || response['editorParams'] || (response['toolbarVersion'] ? {
|
|
4121
4160
|
toolbarVersion: response['toolbarVersion']
|
|
4122
4161
|
} : {});
|
|
4123
4162
|
|
|
4124
|
-
if (response['isAuthenticated'] &&
|
|
4125
|
-
this.
|
|
4163
|
+
if (response['isAuthenticated'] && toolbarParams['toolbarVersion'] && toolbarParams['toolbarVersion'].indexOf('toolbar') === 0) {
|
|
4164
|
+
this.loadToolbar(_objectSpread2(_objectSpread2({}, toolbarParams), {}, {
|
|
4126
4165
|
apiURL: this.instance.get_config('api_host')
|
|
4127
4166
|
}));
|
|
4128
4167
|
}
|
|
4129
4168
|
}
|
|
4130
4169
|
/**
|
|
4131
|
-
* To load the
|
|
4132
|
-
* 1. In the URL hash params
|
|
4133
|
-
* 2. From session storage under the key `
|
|
4170
|
+
* To load the toolbar, we need an access token and other state. That state comes from one of three places:
|
|
4171
|
+
* 1. In the URL hash params
|
|
4172
|
+
* 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page
|
|
4134
4173
|
*/
|
|
4135
4174
|
|
|
4136
4175
|
}, {
|
|
4137
|
-
key: "
|
|
4138
|
-
value: function
|
|
4176
|
+
key: "maybeLoadToolbar",
|
|
4177
|
+
value: function maybeLoadToolbar() {
|
|
4139
4178
|
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4140
4179
|
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4141
4180
|
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
@@ -4157,16 +4196,15 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4157
4196
|
var stateHash = _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state');
|
|
4158
4197
|
|
|
4159
4198
|
var state = stateHash ? JSON.parse(decodeURIComponent(stateHash)) : null;
|
|
4160
|
-
var parseFromUrl = state &&
|
|
4161
|
-
var
|
|
4199
|
+
var parseFromUrl = state && state['action'] === 'ph_authorize';
|
|
4200
|
+
var toolbarParams;
|
|
4162
4201
|
|
|
4163
4202
|
if (parseFromUrl) {
|
|
4164
|
-
// happens if they are initializing the
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
if (editorParams && Object.keys(editorParams).length > 0) {
|
|
4168
|
-
localStorage.setItem('_postHogEditorParams', JSON.stringify(editorParams));
|
|
4203
|
+
// happens if they are initializing the toolbar using an old snippet
|
|
4204
|
+
toolbarParams = state;
|
|
4205
|
+
toolbarParams.source = 'url';
|
|
4169
4206
|
|
|
4207
|
+
if (toolbarParams && Object.keys(toolbarParams).length > 0) {
|
|
4170
4208
|
if (state['desiredHash']) {
|
|
4171
4209
|
// hash that was in the url before the redirect
|
|
4172
4210
|
location.hash = state['desiredHash'];
|
|
@@ -4178,19 +4216,19 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4178
4216
|
}
|
|
4179
4217
|
} else {
|
|
4180
4218
|
// get credentials from localStorage from a previous initialzation
|
|
4181
|
-
|
|
4219
|
+
toolbarParams = JSON.parse(localStorage.getItem('_postHogToolbarParams') || '{}');
|
|
4220
|
+
toolbarParams.source = 'localstorage'; // delete "add-action" or other intent from toolbarParams, otherwise we'll have the same intent
|
|
4182
4221
|
// every time we open the page (e.g. you just visiting your own site an hour later)
|
|
4183
4222
|
|
|
4184
|
-
delete
|
|
4223
|
+
delete toolbarParams.userIntent;
|
|
4185
4224
|
}
|
|
4186
4225
|
|
|
4187
|
-
if (!
|
|
4188
|
-
|
|
4226
|
+
if (!toolbarParams.apiURL) {
|
|
4227
|
+
toolbarParams.apiURL = this.instance.get_config('api_host');
|
|
4189
4228
|
}
|
|
4190
4229
|
|
|
4191
|
-
if (
|
|
4192
|
-
this.
|
|
4193
|
-
|
|
4230
|
+
if (toolbarParams['token'] && this.instance.get_config('token') === toolbarParams['token']) {
|
|
4231
|
+
this.loadToolbar(toolbarParams);
|
|
4194
4232
|
return true;
|
|
4195
4233
|
} else {
|
|
4196
4234
|
return false;
|
|
@@ -4200,33 +4238,61 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4200
4238
|
}
|
|
4201
4239
|
}
|
|
4202
4240
|
}, {
|
|
4203
|
-
key: "
|
|
4204
|
-
value: function
|
|
4241
|
+
key: "loadToolbar",
|
|
4242
|
+
value: function loadToolbar(params) {
|
|
4205
4243
|
var _this = this;
|
|
4206
4244
|
|
|
4207
|
-
if (
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
});
|
|
4245
|
+
if (window['_postHogToolbarLoaded']) {
|
|
4246
|
+
return false;
|
|
4247
|
+
} // only load the toolbar once, even if there are multiple instances of PostHogLib
|
|
4248
|
+
window['_postHogToolbarLoaded'] = true;
|
|
4249
|
+
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');
|
|
4250
|
+
var toolbarUrl = "".concat(host).concat(host.endsWith('/') ? '' : '/', "static/toolbar.js?_ts=").concat(new Date().getTime());
|
|
4251
|
+
var disableToolbarMetrics = !POSTHOG_MANAGED_HOSTS.includes(this.instance.get_config('api_host')) && this.instance.get_config('advanced_disable_toolbar_metrics');
|
|
4252
|
+
|
|
4253
|
+
var toolbarParams = _objectSpread2(_objectSpread2({
|
|
4254
|
+
apiURL: host,
|
|
4255
|
+
// defaults to api_host from the instance config if nothing else set
|
|
4256
|
+
jsURL: host,
|
|
4257
|
+
// defaults to api_host from the instance config if nothing else set
|
|
4258
|
+
token: this.instance.get_config('token')
|
|
4259
|
+
}, params), disableToolbarMetrics ? {
|
|
4260
|
+
instrument: false
|
|
4261
|
+
} : {});
|
|
4225
4262
|
|
|
4226
|
-
|
|
4227
|
-
|
|
4263
|
+
toolbarParams.source;
|
|
4264
|
+
var paramsToPersist = _objectWithoutProperties(toolbarParams, _excluded); // eslint-disable-line
|
|
4228
4265
|
|
|
4229
|
-
|
|
4266
|
+
|
|
4267
|
+
window.localStorage.setItem('_postHogToolbarParams', JSON.stringify(paramsToPersist));
|
|
4268
|
+
loadScript(toolbarUrl, function () {
|
|
4269
|
+
(window['ph_load_toolbar'] || window['ph_load_editor'])(toolbarParams, _this.instance);
|
|
4270
|
+
}); // Turbolinks doesn't fire an onload event but does replace the entire page, including the toolbar
|
|
4271
|
+
|
|
4272
|
+
_register_event(window, 'turbolinks:load', function () {
|
|
4273
|
+
window['_postHogToolbarLoaded'] = false;
|
|
4274
|
+
|
|
4275
|
+
_this.loadToolbar(toolbarParams);
|
|
4276
|
+
});
|
|
4277
|
+
|
|
4278
|
+
return true;
|
|
4279
|
+
}
|
|
4280
|
+
/** @deprecated Use "loadToolbar" instead. */
|
|
4281
|
+
|
|
4282
|
+
}, {
|
|
4283
|
+
key: "_loadEditor",
|
|
4284
|
+
value: function _loadEditor(params) {
|
|
4285
|
+
return this.loadToolbar(params);
|
|
4286
|
+
}
|
|
4287
|
+
/** @deprecated Use "maybeLoadToolbar" instead. */
|
|
4288
|
+
|
|
4289
|
+
}, {
|
|
4290
|
+
key: "maybeLoadEditor",
|
|
4291
|
+
value: function maybeLoadEditor() {
|
|
4292
|
+
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4293
|
+
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4294
|
+
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
4295
|
+
return this.maybeLoadToolbar(location, localStorage, history);
|
|
4230
4296
|
}
|
|
4231
4297
|
}]);
|
|
4232
4298
|
|
|
@@ -6089,7 +6155,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
6089
6155
|
|
|
6090
6156
|
instance._init(token, config, name);
|
|
6091
6157
|
|
|
6092
|
-
instance.toolbar.
|
|
6158
|
+
instance.toolbar.maybeLoadToolbar();
|
|
6093
6159
|
instance.sessionRecording = new SessionRecording(instance);
|
|
6094
6160
|
instance.sessionRecording.startRecordingIfEnabled();
|
|
6095
6161
|
instance.__autocapture_enabled = instance.get_config('autocapture');
|
|
@@ -7300,6 +7366,16 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
7300
7366
|
|
|
7301
7367
|
return !!((_this$sessionRecordin = this.sessionRecording) !== null && _this$sessionRecordin !== void 0 && _this$sessionRecordin.started());
|
|
7302
7368
|
}
|
|
7369
|
+
/**
|
|
7370
|
+
* returns a boolean indicating whether the toolbar loaded
|
|
7371
|
+
* @param toolbarParams
|
|
7372
|
+
*/
|
|
7373
|
+
|
|
7374
|
+
}, {
|
|
7375
|
+
key: "loadToolbar",
|
|
7376
|
+
value: function loadToolbar(params) {
|
|
7377
|
+
return this.toolbar.loadToolbar(params);
|
|
7378
|
+
}
|
|
7303
7379
|
/**
|
|
7304
7380
|
* returns the current config object for the library.
|
|
7305
7381
|
*/
|