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/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
|
|
|
@@ -1645,6 +1681,11 @@ var _info = {
|
|
|
1645
1681
|
|
|
1646
1682
|
return parseFloat(matches[matches.length - 2]);
|
|
1647
1683
|
},
|
|
1684
|
+
browserLanguage: function browserLanguage() {
|
|
1685
|
+
return navigator.language || // Any modern browser
|
|
1686
|
+
navigator.userLanguage // IE11
|
|
1687
|
+
;
|
|
1688
|
+
},
|
|
1648
1689
|
os: function os() {
|
|
1649
1690
|
var a = userAgent;
|
|
1650
1691
|
|
|
@@ -1720,6 +1761,7 @@ var _info = {
|
|
|
1720
1761
|
$host: window.location.host,
|
|
1721
1762
|
$pathname: window.location.pathname,
|
|
1722
1763
|
$browser_version: _info.browserVersion(userAgent, navigator.vendor, window.opera),
|
|
1764
|
+
$browser_language: _info.browserLanguage(),
|
|
1723
1765
|
$screen_height: window.screen.height,
|
|
1724
1766
|
$screen_width: window.screen.width,
|
|
1725
1767
|
$viewport_height: window.innerHeight,
|
|
@@ -4101,6 +4143,9 @@ var Decide = /*#__PURE__*/function () {
|
|
|
4101
4143
|
return Decide;
|
|
4102
4144
|
}();
|
|
4103
4145
|
|
|
4146
|
+
var POSTHOG_MANAGED_HOSTS = ['https://app.posthog.com', 'https://eu.posthog.com'];
|
|
4147
|
+
|
|
4148
|
+
var _excluded = ["source"];
|
|
4104
4149
|
var Toolbar = /*#__PURE__*/function () {
|
|
4105
4150
|
function Toolbar(instance) {
|
|
4106
4151
|
_classCallCheck(this, Toolbar);
|
|
@@ -4111,25 +4156,25 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4111
4156
|
_createClass(Toolbar, [{
|
|
4112
4157
|
key: "afterDecideResponse",
|
|
4113
4158
|
value: function afterDecideResponse(response) {
|
|
4114
|
-
var
|
|
4159
|
+
var toolbarParams = response['toolbarParams'] || response['editorParams'] || (response['toolbarVersion'] ? {
|
|
4115
4160
|
toolbarVersion: response['toolbarVersion']
|
|
4116
4161
|
} : {});
|
|
4117
4162
|
|
|
4118
|
-
if (response['isAuthenticated'] &&
|
|
4119
|
-
this.
|
|
4163
|
+
if (response['isAuthenticated'] && toolbarParams['toolbarVersion'] && toolbarParams['toolbarVersion'].indexOf('toolbar') === 0) {
|
|
4164
|
+
this.loadToolbar(_objectSpread2(_objectSpread2({}, toolbarParams), {}, {
|
|
4120
4165
|
apiURL: this.instance.get_config('api_host')
|
|
4121
4166
|
}));
|
|
4122
4167
|
}
|
|
4123
4168
|
}
|
|
4124
4169
|
/**
|
|
4125
|
-
* To load the
|
|
4126
|
-
* 1. In the URL hash params
|
|
4127
|
-
* 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
|
|
4128
4173
|
*/
|
|
4129
4174
|
|
|
4130
4175
|
}, {
|
|
4131
|
-
key: "
|
|
4132
|
-
value: function
|
|
4176
|
+
key: "maybeLoadToolbar",
|
|
4177
|
+
value: function maybeLoadToolbar() {
|
|
4133
4178
|
var location = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location;
|
|
4134
4179
|
var localStorage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
4135
4180
|
var history = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.history;
|
|
@@ -4151,16 +4196,15 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4151
4196
|
var stateHash = _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state');
|
|
4152
4197
|
|
|
4153
4198
|
var state = stateHash ? JSON.parse(decodeURIComponent(stateHash)) : null;
|
|
4154
|
-
var parseFromUrl = state &&
|
|
4155
|
-
var
|
|
4199
|
+
var parseFromUrl = state && state['action'] === 'ph_authorize';
|
|
4200
|
+
var toolbarParams;
|
|
4156
4201
|
|
|
4157
4202
|
if (parseFromUrl) {
|
|
4158
|
-
// happens if they are initializing the
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
if (editorParams && Object.keys(editorParams).length > 0) {
|
|
4162
|
-
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';
|
|
4163
4206
|
|
|
4207
|
+
if (toolbarParams && Object.keys(toolbarParams).length > 0) {
|
|
4164
4208
|
if (state['desiredHash']) {
|
|
4165
4209
|
// hash that was in the url before the redirect
|
|
4166
4210
|
location.hash = state['desiredHash'];
|
|
@@ -4172,19 +4216,19 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4172
4216
|
}
|
|
4173
4217
|
} else {
|
|
4174
4218
|
// get credentials from localStorage from a previous initialzation
|
|
4175
|
-
|
|
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
|
|
4176
4221
|
// every time we open the page (e.g. you just visiting your own site an hour later)
|
|
4177
4222
|
|
|
4178
|
-
delete
|
|
4223
|
+
delete toolbarParams.userIntent;
|
|
4179
4224
|
}
|
|
4180
4225
|
|
|
4181
|
-
if (!
|
|
4182
|
-
|
|
4226
|
+
if (!toolbarParams.apiURL) {
|
|
4227
|
+
toolbarParams.apiURL = this.instance.get_config('api_host');
|
|
4183
4228
|
}
|
|
4184
4229
|
|
|
4185
|
-
if (
|
|
4186
|
-
this.
|
|
4187
|
-
|
|
4230
|
+
if (toolbarParams['token'] && this.instance.get_config('token') === toolbarParams['token']) {
|
|
4231
|
+
this.loadToolbar(toolbarParams);
|
|
4188
4232
|
return true;
|
|
4189
4233
|
} else {
|
|
4190
4234
|
return false;
|
|
@@ -4194,33 +4238,61 @@ var Toolbar = /*#__PURE__*/function () {
|
|
|
4194
4238
|
}
|
|
4195
4239
|
}
|
|
4196
4240
|
}, {
|
|
4197
|
-
key: "
|
|
4198
|
-
value: function
|
|
4241
|
+
key: "loadToolbar",
|
|
4242
|
+
value: function loadToolbar(params) {
|
|
4199
4243
|
var _this = this;
|
|
4200
4244
|
|
|
4201
|
-
if (
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
});
|
|
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
|
+
} : {});
|
|
4219
4262
|
|
|
4220
|
-
|
|
4221
|
-
|
|
4263
|
+
toolbarParams.source;
|
|
4264
|
+
var paramsToPersist = _objectWithoutProperties(toolbarParams, _excluded); // eslint-disable-line
|
|
4222
4265
|
|
|
4223
|
-
|
|
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);
|
|
4224
4296
|
}
|
|
4225
4297
|
}]);
|
|
4226
4298
|
|
|
@@ -6083,7 +6155,7 @@ var create_mplib = function create_mplib(token, config, name) {
|
|
|
6083
6155
|
|
|
6084
6156
|
instance._init(token, config, name);
|
|
6085
6157
|
|
|
6086
|
-
instance.toolbar.
|
|
6158
|
+
instance.toolbar.maybeLoadToolbar();
|
|
6087
6159
|
instance.sessionRecording = new SessionRecording(instance);
|
|
6088
6160
|
instance.sessionRecording.startRecordingIfEnabled();
|
|
6089
6161
|
instance.__autocapture_enabled = instance.get_config('autocapture');
|
|
@@ -7294,6 +7366,16 @@ var PostHog = /*#__PURE__*/function () {
|
|
|
7294
7366
|
|
|
7295
7367
|
return !!((_this$sessionRecordin = this.sessionRecording) !== null && _this$sessionRecordin !== void 0 && _this$sessionRecordin.started());
|
|
7296
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
|
+
}
|
|
7297
7379
|
/**
|
|
7298
7380
|
* returns the current config object for the library.
|
|
7299
7381
|
*/
|