posthog-js 1.85.4 → 1.86.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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.85.4",
3
+ "version": "1.86.0",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",
package/lib/src/decide.js CHANGED
@@ -37,9 +37,9 @@ var Decide = /** @class */ (function () {
37
37
  this.instance._send_request("".concat(this.instance.config.api_host, "/decide/?v=3"), { data: encoded_data, verbose: true }, { method: 'POST' }, function (response) { return _this.parseDecideResponse(response); });
38
38
  };
39
39
  Decide.prototype.parseDecideResponse = function (response) {
40
- var e_1, _a, e_2, _b;
40
+ var e_1, _a;
41
41
  var _this = this;
42
- var _c, _d;
42
+ var _b, _c;
43
43
  this.instance.featureFlags.setReloadingPaused(false);
44
44
  // :TRICKY: Reload - start another request if queued!
45
45
  this.instance.featureFlags._startReloadTimer();
@@ -55,30 +55,13 @@ var Decide = /** @class */ (function () {
55
55
  return;
56
56
  }
57
57
  this.instance.toolbar.afterDecideResponse(response);
58
- (_c = this.instance.sessionRecording) === null || _c === void 0 ? void 0 : _c.afterDecideResponse(response);
58
+ (_b = this.instance.sessionRecording) === null || _b === void 0 ? void 0 : _b.afterDecideResponse(response);
59
59
  autocapture.afterDecideResponse(response, this.instance);
60
- (_d = this.instance.webPerformance) === null || _d === void 0 ? void 0 : _d.afterDecideResponse(response);
60
+ (_c = this.instance.webPerformance) === null || _c === void 0 ? void 0 : _c.afterDecideResponse(response);
61
+ this.instance._afterDecideResponse(response);
61
62
  if (!this.instance.config.advanced_disable_feature_flags_on_first_load) {
62
63
  this.instance.featureFlags.receivedFeatureFlags(response);
63
64
  }
64
- this.instance['compression'] = {};
65
- if (response['supportedCompression'] && !this.instance.config.disable_compression) {
66
- var compression = {};
67
- try {
68
- for (var _e = __values(response['supportedCompression']), _f = _e.next(); !_f.done; _f = _e.next()) {
69
- var method = _f.value;
70
- compression[method] = true;
71
- }
72
- }
73
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
74
- finally {
75
- try {
76
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
77
- }
78
- finally { if (e_1) throw e_1.error; }
79
- }
80
- this.instance['compression'] = compression;
81
- }
82
65
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
66
  // @ts-ignore
84
67
  var surveysGenerator = window === null || window === void 0 ? void 0 : window.extendPostHogWithSurveys;
@@ -124,17 +107,17 @@ var Decide = /** @class */ (function () {
124
107
  };
125
108
  var this_1 = this;
126
109
  try {
127
- for (var _g = __values(response['siteApps']), _h = _g.next(); !_h.done; _h = _g.next()) {
128
- var _j = _h.value, id = _j.id, url = _j.url;
110
+ for (var _d = __values(response['siteApps']), _e = _d.next(); !_e.done; _e = _d.next()) {
111
+ var _f = _e.value, id = _f.id, url = _f.url;
129
112
  _loop_1(id, url);
130
113
  }
131
114
  }
132
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
115
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
133
116
  finally {
134
117
  try {
135
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
118
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
136
119
  }
137
- finally { if (e_2) throw e_2.error; }
120
+ finally { if (e_1) throw e_1.error; }
138
121
  }
139
122
  }
140
123
  else if (response['siteApps'].length > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGzE,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM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SACL;QAED,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE;YACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE;gBACvC,IAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAA;wCAChC,EAAE,EAAE,GAAG;oBAChB,IAAM,SAAS,GAAG;wBACd,OAAO;wBACP,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;qBACjF,CAAC,IAAI,CAAC,EAAE,CAAC,CAET;oBAAC,MAAc,CAAC,0BAAmB,EAAE,CAAE,CAAC,GAAG,OAAK,QAAQ,CAAA;oBAEzD,UAAU,CAAC,SAAS,EAAE,UAAC,GAAG;wBACtB,IAAI,GAAG,EAAE;4BACL,MAAM,CAAC,KAAK,CAAC,8DAAuD,EAAE,CAAE,EAAE,GAAG,CAAC,CAAA;yBACjF;oBACL,CAAC,CAAC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACnG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AA9HD,IA8HC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, _isUndefined, loadScript, logger } from './utils'\nimport { PostHog } from './posthog-core'\nimport { Compression, DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.config.token,\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.config.advanced_disable_feature_flags ||\n this.instance.config.advanced_disable_feature_flags_on_first_load ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.config.api_host}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n this.instance.featureFlags.setReloadingPaused(false)\n // :TRICKY: Reload - start another request if queued!\n this.instance.featureFlags._startReloadTimer()\n\n if (response?.status === 0) {\n logger.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n logger.info('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n\n if (!this.instance.config.advanced_disable_feature_flags_on_first_load) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n this.instance['compression'] = {}\n if (response['supportedCompression'] && !this.instance.config.disable_compression) {\n const compression: Partial<Record<Compression, boolean>> = {}\n for (const method of response['supportedCompression']) {\n compression[method] = true\n }\n this.instance['compression'] = compression\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const surveysGenerator = window?.extendPostHogWithSurveys\n\n if (response['surveys'] && !surveysGenerator) {\n loadScript(this.instance.config.api_host + `/static/surveys.js`, (err) => {\n if (err) {\n return logger.error(`Could not load surveys script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithSurveys(this.instance)\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const exceptionAutoCaptureAddedToWindow = window?.extendPostHogWithExceptionAutoCapture\n if (\n response['autocaptureExceptions'] &&\n !!response['autocaptureExceptions'] &&\n _isUndefined(exceptionAutoCaptureAddedToWindow)\n ) {\n loadScript(this.instance.config.api_host + `/static/exception-autocapture.js`, (err) => {\n if (err) {\n return logger.error(`Could not load exception autocapture script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithExceptionAutocapture(this.instance, response)\n })\n }\n\n if (response['siteApps']) {\n if (this.instance.config.opt_in_site_apps) {\n const apiHost = this.instance.config.api_host\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n ;(window as any)[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n logger.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n logger.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGzE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,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;qBACjF,CAAC,IAAI,CAAC,EAAE,CAAC,CAET;oBAAC,MAAc,CAAC,0BAAmB,EAAE,CAAE,CAAC,GAAG,OAAK,QAAQ,CAAA;oBAEzD,UAAU,CAAC,SAAS,EAAE,UAAC,GAAG;wBACtB,IAAI,GAAG,EAAE;4BACL,MAAM,CAAC,KAAK,CAAC,8DAAuD,EAAE,CAAE,EAAE,GAAG,CAAC,CAAA;yBACjF;oBACL,CAAC,CAAC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACnG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AAtHD,IAsHC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, _isUndefined, loadScript, logger } from './utils'\nimport { PostHog } from './posthog-core'\nimport { DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.config.token,\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.config.advanced_disable_feature_flags ||\n this.instance.config.advanced_disable_feature_flags_on_first_load ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.config.api_host}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n this.instance.featureFlags.setReloadingPaused(false)\n // :TRICKY: Reload - start another request if queued!\n this.instance.featureFlags._startReloadTimer()\n\n if (response?.status === 0) {\n logger.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n logger.info('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n this.instance._afterDecideResponse(response)\n\n if (!this.instance.config.advanced_disable_feature_flags_on_first_load) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const surveysGenerator = window?.extendPostHogWithSurveys\n\n if (response['surveys'] && !surveysGenerator) {\n loadScript(this.instance.config.api_host + `/static/surveys.js`, (err) => {\n if (err) {\n return logger.error(`Could not load surveys script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithSurveys(this.instance)\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const exceptionAutoCaptureAddedToWindow = window?.extendPostHogWithExceptionAutoCapture\n if (\n response['autocaptureExceptions'] &&\n !!response['autocaptureExceptions'] &&\n _isUndefined(exceptionAutoCaptureAddedToWindow)\n ) {\n loadScript(this.instance.config.api_host + `/static/exception-autocapture.js`, (err) => {\n if (err) {\n return logger.error(`Could not load exception autocapture script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithExceptionAutocapture(this.instance, response)\n })\n }\n\n if (response['siteApps']) {\n if (this.instance.config.opt_in_site_apps) {\n const apiHost = this.instance.config.api_host\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n ;(window as any)[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n logger.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n logger.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
@@ -6,7 +6,7 @@ import { Toolbar } from './extensions/toolbar';
6
6
  import { RequestQueue } from './request-queue';
7
7
  import { RetryQueue } from './retry-queue';
8
8
  import { SessionIdManager } from './sessionid';
9
- import { AutocaptureConfig, CaptureOptions, CaptureResult, Compression, EarlyAccessFeatureCallback, GDPROptions, isFeatureEnabledOptions, JSC, JsonType, OptInOutCapturingOptions, PostHogConfig, Properties, Property, RequestCallback, SessionIdChangedCallback, SnippetArrayItem, ToolbarParams, XHROptions } from './types';
9
+ import { AutocaptureConfig, CaptureOptions, CaptureResult, Compression, DecideResponse, EarlyAccessFeatureCallback, GDPROptions, isFeatureEnabledOptions, JSC, JsonType, OptInOutCapturingOptions, PostHogConfig, Properties, Property, RequestCallback, SessionIdChangedCallback, SnippetArrayItem, ToolbarParams, XHROptions } from './types';
10
10
  import { SentryIntegration } from './extensions/sentry-integration';
11
11
  import { PageViewManager } from './page-view';
12
12
  import { PostHogSurveys } from './posthog-surveys';
@@ -39,6 +39,7 @@ export declare class PostHog {
39
39
  __request_queue: [url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback][];
40
40
  __autocapture: boolean | AutocaptureConfig | undefined;
41
41
  decideEndpointWasHit: boolean;
42
+ analyticsDefaultEndpoint: string;
42
43
  SentryIntegration: typeof SentryIntegration;
43
44
  segmentIntegration: () => any;
44
45
  /** DEPRECATED: We keep this to support existing usage but now one should just call .setPersonProperties */
@@ -65,6 +66,7 @@ export declare class PostHog {
65
66
  */
66
67
  init(token: string, config?: Partial<PostHogConfig>, name?: string): PostHog | void;
67
68
  _init(token: string, config?: Partial<PostHogConfig>, name?: string, initComplete?: (instance: PostHog) => void): void;
69
+ _afterDecideResponse(response: DecideResponse): void;
68
70
  _loaded(): void;
69
71
  _start_queue_if_opted_in(): void;
70
72
  _dom_loaded(): void;
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __values = (this && this.__values) || function(o) {
13
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
14
+ if (m) return m.call(o);
15
+ if (o && typeof o.length === "number") return {
16
+ next: function () {
17
+ if (o && i >= o.length) o = void 0;
18
+ return { value: o && o[i++], done: !o };
19
+ }
20
+ };
21
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
22
+ };
12
23
  var __read = (this && this.__read) || function (o, n) {
13
24
  var m = typeof Symbol === "function" && o[Symbol.iterator];
14
25
  if (!m) return o;
@@ -249,6 +260,7 @@ var PostHog = /** @class */ (function () {
249
260
  this.__loaded_recorder_version = undefined;
250
261
  this.__autocapture = undefined;
251
262
  this._jsc = function () { };
263
+ this.analyticsDefaultEndpoint = '/e/';
252
264
  this.featureFlags = new PostHogFeatureFlags(this);
253
265
  this.toolbar = new Toolbar(this);
254
266
  this.pageViewManager = new PageViewManager();
@@ -430,6 +442,31 @@ var PostHog = /** @class */ (function () {
430
442
  updateInitComplete('syncCode')();
431
443
  };
432
444
  // Private methods
445
+ PostHog.prototype._afterDecideResponse = function (response) {
446
+ var e_1, _a;
447
+ var _b;
448
+ this.compression = {};
449
+ if (response.supportedCompression && !this.config.disable_compression) {
450
+ var compression = {};
451
+ try {
452
+ for (var _c = __values(response['supportedCompression']), _d = _c.next(); !_d.done; _d = _c.next()) {
453
+ var method = _d.value;
454
+ compression[method] = true;
455
+ }
456
+ }
457
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
458
+ finally {
459
+ try {
460
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
461
+ }
462
+ finally { if (e_1) throw e_1.error; }
463
+ }
464
+ this.compression = compression;
465
+ }
466
+ if ((_b = response.analytics) === null || _b === void 0 ? void 0 : _b.endpoint) {
467
+ this.analyticsDefaultEndpoint = response.analytics.endpoint;
468
+ }
469
+ };
433
470
  PostHog.prototype._loaded = function () {
434
471
  // Pause `reloadFeatureFlags` calls in config.loaded callback.
435
472
  // These feature flags are loaded in the decide call made right
@@ -744,7 +781,7 @@ var PostHog = /** @class */ (function () {
744
781
  }
745
782
  logger.info('send', data);
746
783
  var jsonData = JSON.stringify(data);
747
- var url = this.config.api_host + (options.endpoint || '/e/');
784
+ var url = this.config.api_host + (options.endpoint || this.analyticsDefaultEndpoint);
748
785
  var has_unique_traits = options !== __NOOPTIONS;
749
786
  if (this.config.request_batching && (!has_unique_traits || options._batchKey) && !options.send_instantly) {
750
787
  this._requestQueue.enqueue(url, data, options);