posthog-js 1.275.1 → 1.275.3

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.
Files changed (40) hide show
  1. package/dist/array.full.es5.js +1 -1
  2. package/dist/array.full.es5.js.map +1 -1
  3. package/dist/array.full.js +1 -1
  4. package/dist/array.full.js.map +1 -1
  5. package/dist/array.full.no-external.js +1 -1
  6. package/dist/array.full.no-external.js.map +1 -1
  7. package/dist/array.js +1 -1
  8. package/dist/array.js.map +1 -1
  9. package/dist/array.no-external.js +1 -1
  10. package/dist/array.no-external.js.map +1 -1
  11. package/dist/customizations.full.js +1 -1
  12. package/dist/lazy-recorder.js +1 -1
  13. package/dist/main.js +1 -1
  14. package/dist/main.js.map +1 -1
  15. package/dist/module.d.ts +6 -1
  16. package/dist/module.full.d.ts +6 -1
  17. package/dist/module.full.js +1 -1
  18. package/dist/module.full.js.map +1 -1
  19. package/dist/module.full.no-external.d.ts +6 -1
  20. package/dist/module.full.no-external.js +1 -1
  21. package/dist/module.full.no-external.js.map +1 -1
  22. package/dist/module.js +1 -1
  23. package/dist/module.js.map +1 -1
  24. package/dist/module.no-external.d.ts +6 -1
  25. package/dist/module.no-external.js +1 -1
  26. package/dist/module.no-external.js.map +1 -1
  27. package/dist/posthog-recorder.js +1 -1
  28. package/dist/src/posthog-core.d.ts +1 -0
  29. package/dist/src/posthog-persistence.d.ts +5 -1
  30. package/dist/surveys-preview.d.ts +6 -1
  31. package/lib/package.json +1 -1
  32. package/lib/src/extensions/sentry-integration.js +0 -1
  33. package/lib/src/extensions/sentry-integration.js.map +1 -1
  34. package/lib/src/posthog-core.d.ts +1 -0
  35. package/lib/src/posthog-core.js +26 -12
  36. package/lib/src/posthog-core.js.map +1 -1
  37. package/lib/src/posthog-persistence.d.ts +5 -1
  38. package/lib/src/posthog-persistence.js +4 -0
  39. package/lib/src/posthog-persistence.js.map +1 -1
  40. package/package.json +2 -2
@@ -1541,6 +1541,7 @@ export declare class PostHog {
1541
1541
  * @param metricValue The value of the metric to capture.
1542
1542
  */
1543
1543
  captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
1544
+ private _checkLocalStorageForDebug;
1544
1545
  }
1545
1546
  export declare function init_from_snippet(): void;
1546
1547
  export declare function init_as_module(): PostHog;
@@ -19,7 +19,11 @@ export declare class PostHogPersistence {
19
19
  * @param {boolean=} isDisabled should persistence be disabled (e.g. because of consent management)
20
20
  */
21
21
  constructor(config: PostHogConfig, isDisabled?: boolean);
22
- isDisabled(): boolean;
22
+ /**
23
+ * Returns whether persistence is disabled. Only available in SDKs > 1.257.1. Do not use on extensions, otherwise
24
+ * it'll break backwards compatibility for any version before 1.257.1.
25
+ */
26
+ isDisabled?(): boolean;
23
27
  private _buildStorage;
24
28
  properties(): Properties;
25
29
  load(): void;
@@ -2176,7 +2176,11 @@ declare class PostHogPersistence {
2176
2176
  * @param {boolean=} isDisabled should persistence be disabled (e.g. because of consent management)
2177
2177
  */
2178
2178
  constructor(config: PostHogConfig, isDisabled?: boolean);
2179
- isDisabled(): boolean;
2179
+ /**
2180
+ * Returns whether persistence is disabled. Only available in SDKs > 1.257.1. Do not use on extensions, otherwise
2181
+ * it'll break backwards compatibility for any version before 1.257.1.
2182
+ */
2183
+ isDisabled?(): boolean;
2180
2184
  private _buildStorage;
2181
2185
  properties(): Properties;
2182
2186
  load(): void;
@@ -4208,6 +4212,7 @@ declare class PostHog {
4208
4212
  * @param metricValue The value of the metric to capture.
4209
4213
  */
4210
4214
  captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
4215
+ private _checkLocalStorageForDebug;
4211
4216
  }
4212
4217
 
4213
4218
  declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): any;
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.275.1",
3
+ "version": "1.275.3",
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",
@@ -59,7 +59,6 @@ function createEventProcessor(_posthog, _a) {
59
59
  // PostHog Exception Properties,
60
60
  $exception_message: ((_b = exceptions[0]) === null || _b === void 0 ? void 0 : _b.value) || event.message,
61
61
  $exception_type: (_c = exceptions[0]) === null || _c === void 0 ? void 0 : _c.type,
62
- $exception_personURL: personUrl,
63
62
  $exception_level: event.level,
64
63
  $exception_list: exceptionList,
65
64
  // Sentry Exception Properties
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-integration.js","sourceRoot":"","sources":["../../../src/extensions/sentry-integration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;;;;;;AAqDH,oDAgFC;AAGD,8CAQC;AA7FD,IAAM,IAAI,GAAG,YAAY,CAAA;AAEzB,SAAgB,oBAAoB,CAChC,QAAiB,EACjB,EAMgC;QANhC,qBAM8B,EAAE,KAAA,EAL5B,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,MAAM,YAAA,EACN,yBAA6B,EAA7B,iBAAiB,mBAAG,CAAC,OAAO,CAAC,KAAA,EAC7B,+BAA8B,EAA9B,uBAAuB,mBAAG,IAAI,KAAA;IAGlC,OAAO,UAAC,KAAK;;QACT,IAAM,kBAAkB,GAAG,iBAAiB,KAAK,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAsB,CAAC,CAAA;QAChH,IAAI,CAAC,kBAAkB,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;QAC3D,IAAI,CAAC,KAAK,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,GAAG,EAAE,CAAA;QAEhC,IAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,WAAW,CAChD,IAAI,EACJ,mBAAY,QAAQ,CAAC,MAAM,CAAC,KAAK,qBAAW,QAAQ,CAAC,eAAe,EAAE,CAAE,C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,IA8BC;AA9BY,8CAAiB","sourcesContent":["/**\n * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog\n *\n * ### Usage\n *\n * Sentry.init({\n * dsn: 'https://example',\n * integrations: [\n * new posthog.SentryIntegration(posthog)\n * ]\n * })\n *\n * @param {Object} [posthog] The posthog object\n * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry\n * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry\n * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)\n * @param {SeverityLevel[] | '*'} [severityAllowList] Optional: send events matching the provided levels. Use '*' to send all events (default: ['error'])\n * @param {boolean} [sendExceptionsToPostHog] Optional: capture exceptions as events in PostHog (default: true)\n */\n\nimport { PostHog } from '../posthog-core'\nimport { SeverityLevel } from '../types'\n\n// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes\n// We only use a small subset of the types, so we can just define the integration overall and use any for the rest\n\n// import {\n// Event as _SentryEvent,\n// EventProcessor as _SentryEventProcessor,\n// Hub as _SentryHub,\n// Integration as _SentryIntegration,\n// SeverityLevel as _SeverityLevel,\n// IntegrationClass as _SentryIntegrationClass,\n// } from '@sentry/types'\n\n// Uncomment the above and comment the below to get type checking for development\n\ntype _SentryEvent = any\ntype _SentryException = any\ntype _SentryEventProcessor = any\ntype _SentryHub = any\n\ninterface _SentryIntegration {\n name: string\n processEvent(event: _SentryEvent): _SentryEvent\n}\n\ninterface _SentryIntegrationClass {\n name: string\n setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void\n}\n\ninterface SentryExceptionProperties {\n $sentry_event_id: any\n $sentry_exception: any\n $sentry_exception_message: any\n $sentry_exception_type: any\n $sentry_tags: any\n $sentry_url?: string\n}\n\nexport type SentryIntegrationOptions = {\n organization?: string\n projectId?: number\n prefix?: string\n severityAllowList?: SeverityLevel[] | '*'\n sendExceptionsToPostHog?: boolean\n}\n\nconst NAME = 'posthog-js'\n\nexport function createEventProcessor(\n _posthog: PostHog,\n {\n organization,\n projectId,\n prefix,\n severityAllowList = ['error'],\n sendExceptionsToPostHog = true,\n }: SentryIntegrationOptions = {}\n): (event: _SentryEvent) => _SentryEvent {\n return (event) => {\n const shouldProcessLevel = severityAllowList === '*' || severityAllowList.includes(event.level as SeverityLevel)\n if (!shouldProcessLevel || !_posthog.__loaded) return event\n if (!event.tags) event.tags = {}\n\n const personUrl = _posthog.requestRouter.endpointFor(\n 'ui',\n `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}`\n )\n event.tags['PostHog Person URL'] = personUrl\n if (_posthog.sessionRecordingStarted()) {\n event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true })\n }\n\n const exceptions: _SentryException[] = event.exception?.values || []\n\n const exceptionList = exceptions.map((exception) => {\n return {\n ...exception,\n stacktrace: exception.stacktrace\n ? {\n ...exception.stacktrace,\n type: 'raw',\n frames: (exception.stacktrace.frames || []).map((frame: any) => {\n return { ...frame, platform: 'web:javascript' }\n }),\n }\n : undefined,\n }\n })\n\n const data: SentryExceptionProperties & {\n // two properties added to match any exception auto-capture\n // added manually to avoid any dependency on the lazily loaded content\n $exception_message: any\n $exception_type: any\n $exception_list: any\n $exception_personURL: string\n $exception_level: SeverityLevel\n } = {\n // PostHog Exception Properties,\n $exception_message: exceptions[0]?.value || event.message,\n $exception_type: exceptions[0]?.type,\n $exception_personURL: personUrl,\n $exception_level: event.level,\n $exception_list: exceptionList,\n // Sentry Exception Properties\n $sentry_event_id: event.event_id,\n $sentry_exception: event.exception,\n $sentry_exception_message: exceptions[0]?.value || event.message,\n $sentry_exception_type: exceptions[0]?.type,\n $sentry_tags: event.tags,\n }\n\n if (organization && projectId) {\n data['$sentry_url'] =\n (prefix || 'https://sentry.io/organizations/') +\n organization +\n '/issues/?project=' +\n projectId +\n '&query=' +\n event.event_id\n }\n\n if (sendExceptionsToPostHog) {\n _posthog.exceptions.sendExceptionEvent(data)\n }\n\n return event\n }\n}\n\n// V8 integration - function based\nexport function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration {\n const processor = createEventProcessor(_posthog, options)\n return {\n name: NAME,\n processEvent(event) {\n return processor(event)\n },\n }\n}\n// V7 integration - class based\nexport class SentryIntegration implements _SentryIntegrationClass {\n name: string\n\n setupOnce: (\n addGlobalEventProcessor: (callback: _SentryEventProcessor) => void,\n getCurrentHub: () => _SentryHub\n ) => void\n\n constructor(\n _posthog: PostHog,\n organization?: string,\n projectId?: number,\n prefix?: string,\n severityAllowList?: SeverityLevel[] | '*',\n sendExceptionsToPostHog?: boolean\n ) {\n // setupOnce gets called by Sentry when it intializes the plugin\n this.name = NAME\n this.setupOnce = function (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void) {\n addGlobalEventProcessor(\n createEventProcessor(_posthog, {\n organization,\n projectId,\n prefix,\n severityAllowList,\n sendExceptionsToPostHog: sendExceptionsToPostHog ?? true,\n })\n )\n }\n }\n}\n"]}
1
+ {"version":3,"file":"sentry-integration.js","sourceRoot":"","sources":["../../../src/extensions/sentry-integration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;;;;;;AAqDH,oDA8EC;AAGD,8CAQC;AA3FD,IAAM,IAAI,GAAG,YAAY,CAAA;AAEzB,SAAgB,oBAAoB,CAChC,QAAiB,EACjB,EAMgC;QANhC,qBAM8B,EAAE,KAAA,EAL5B,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,MAAM,YAAA,EACN,yBAA6B,EAA7B,iBAAiB,mBAAG,CAAC,OAAO,CAAC,KAAA,EAC7B,+BAA8B,EAA9B,uBAAuB,mBAAG,IAAI,KAAA;IAGlC,OAAO,UAAC,KAAK;;QACT,IAAM,kBAAkB,GAAG,iBAAiB,KAAK,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAsB,CAAC,CAAA;QAChH,IA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,uBAAuB,CACnB,oBAAoB,CAAC,QAAQ,EAAE;gBAC3B,YAAY,cAAA;gBACZ,SAAS,WAAA;gBACT,MAAM,QAAA;gBACN,iBAAiB,mBAAA;gBACjB,uBAAuB,EAAE,uBAAuB,aAAvB,uBAAuB,cAAvB,uBAAuB,GAAI,IAAI;aAC3D,CAAC,CACL,CAAA;QACL,CAAC,CAAA;IACL,CAAC;IACL,wBAAC;AAAD,CAAC,AA9BD,IA8BC;AA9BY,8CAAiB","sourcesContent":["/**\n * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog\n *\n * ### Usage\n *\n * Sentry.init({\n * dsn: 'https://example',\n * integrations: [\n * new posthog.SentryIntegration(posthog)\n * ]\n * })\n *\n * @param {Object} [posthog] The posthog object\n * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry\n * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry\n * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)\n * @param {SeverityLevel[] | '*'} [severityAllowList] Optional: send events matching the provided levels. Use '*' to send all events (default: ['error'])\n * @param {boolean} [sendExceptionsToPostHog] Optional: capture exceptions as events in PostHog (default: true)\n */\n\nimport { PostHog } from '../posthog-core'\nimport { SeverityLevel } from '../types'\n\n// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes\n// We only use a small subset of the types, so we can just define the integration overall and use any for the rest\n\n// import {\n// Event as _SentryEvent,\n// EventProcessor as _SentryEventProcessor,\n// Hub as _SentryHub,\n// Integration as _SentryIntegration,\n// SeverityLevel as _SeverityLevel,\n// IntegrationClass as _SentryIntegrationClass,\n// } from '@sentry/types'\n\n// Uncomment the above and comment the below to get type checking for development\n\ntype _SentryEvent = any\ntype _SentryException = any\ntype _SentryEventProcessor = any\ntype _SentryHub = any\n\ninterface _SentryIntegration {\n name: string\n processEvent(event: _SentryEvent): _SentryEvent\n}\n\ninterface _SentryIntegrationClass {\n name: string\n setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void\n}\n\ninterface SentryExceptionProperties {\n $sentry_event_id: any\n $sentry_exception: any\n $sentry_exception_message: any\n $sentry_exception_type: any\n $sentry_tags: any\n $sentry_url?: string\n}\n\nexport type SentryIntegrationOptions = {\n organization?: string\n projectId?: number\n prefix?: string\n severityAllowList?: SeverityLevel[] | '*'\n sendExceptionsToPostHog?: boolean\n}\n\nconst NAME = 'posthog-js'\n\nexport function createEventProcessor(\n _posthog: PostHog,\n {\n organization,\n projectId,\n prefix,\n severityAllowList = ['error'],\n sendExceptionsToPostHog = true,\n }: SentryIntegrationOptions = {}\n): (event: _SentryEvent) => _SentryEvent {\n return (event) => {\n const shouldProcessLevel = severityAllowList === '*' || severityAllowList.includes(event.level as SeverityLevel)\n if (!shouldProcessLevel || !_posthog.__loaded) return event\n if (!event.tags) event.tags = {}\n\n const personUrl = _posthog.requestRouter.endpointFor(\n 'ui',\n `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}`\n )\n event.tags['PostHog Person URL'] = personUrl\n if (_posthog.sessionRecordingStarted()) {\n event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true })\n }\n\n const exceptions: _SentryException[] = event.exception?.values || []\n\n const exceptionList = exceptions.map((exception) => {\n return {\n ...exception,\n stacktrace: exception.stacktrace\n ? {\n ...exception.stacktrace,\n type: 'raw',\n frames: (exception.stacktrace.frames || []).map((frame: any) => {\n return { ...frame, platform: 'web:javascript' }\n }),\n }\n : undefined,\n }\n })\n\n const data: SentryExceptionProperties & {\n // two properties added to match any exception auto-capture\n // added manually to avoid any dependency on the lazily loaded content\n $exception_message: any\n $exception_type: any\n $exception_list: any\n $exception_level: SeverityLevel\n } = {\n // PostHog Exception Properties,\n $exception_message: exceptions[0]?.value || event.message,\n $exception_type: exceptions[0]?.type,\n $exception_level: event.level,\n $exception_list: exceptionList,\n // Sentry Exception Properties\n $sentry_event_id: event.event_id,\n $sentry_exception: event.exception,\n $sentry_exception_message: exceptions[0]?.value || event.message,\n $sentry_exception_type: exceptions[0]?.type,\n $sentry_tags: event.tags,\n }\n\n if (organization && projectId) {\n data['$sentry_url'] =\n (prefix || 'https://sentry.io/organizations/') +\n organization +\n '/issues/?project=' +\n projectId +\n '&query=' +\n event.event_id\n }\n\n if (sendExceptionsToPostHog) {\n _posthog.exceptions.sendExceptionEvent(data)\n }\n\n return event\n }\n}\n\n// V8 integration - function based\nexport function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration {\n const processor = createEventProcessor(_posthog, options)\n return {\n name: NAME,\n processEvent(event) {\n return processor(event)\n },\n }\n}\n// V7 integration - class based\nexport class SentryIntegration implements _SentryIntegrationClass {\n name: string\n\n setupOnce: (\n addGlobalEventProcessor: (callback: _SentryEventProcessor) => void,\n getCurrentHub: () => _SentryHub\n ) => void\n\n constructor(\n _posthog: PostHog,\n organization?: string,\n projectId?: number,\n prefix?: string,\n severityAllowList?: SeverityLevel[] | '*',\n sendExceptionsToPostHog?: boolean\n ) {\n // setupOnce gets called by Sentry when it intializes the plugin\n this.name = NAME\n this.setupOnce = function (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void) {\n addGlobalEventProcessor(\n createEventProcessor(_posthog, {\n organization,\n projectId,\n prefix,\n severityAllowList,\n sendExceptionsToPostHog: sendExceptionsToPostHog ?? true,\n })\n )\n }\n }\n}\n"]}
@@ -1541,6 +1541,7 @@ export declare class PostHog {
1541
1541
  * @param metricValue The value of the metric to capture.
1542
1542
  */
1543
1543
  captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
1544
+ private _checkLocalStorageForDebug;
1544
1545
  }
1545
1546
  export declare function init_from_snippet(): void;
1546
1547
  export declare function init_as_module(): PostHog;
@@ -394,11 +394,14 @@ var PostHog = /** @class */ (function () {
394
394
  return this;
395
395
  }
396
396
  if (this.__loaded) {
397
- logger_1.logger.warn('You have already initialized PostHog! Re-initializing is a no-op');
397
+ // need to be able to log before having processed debug config
398
+ // eslint-disable-next-line no-console
399
+ console.warn('[PostHog.js]', 'You have already initialized PostHog! Re-initializing is a no-op');
398
400
  return this;
399
401
  }
400
402
  this.__loaded = true;
401
403
  this.config = {}; // will be set right below
404
+ config.debug = this._checkLocalStorageForDebug(config.debug);
402
405
  this._originalUserConfig = config; // Store original user config for migration
403
406
  this._triggered_notifs = [];
404
407
  if (config.person_profiles) {
@@ -2210,16 +2213,24 @@ var PostHog = /** @class */ (function () {
2210
2213
  this.config.persistence === 'sessionStorage' || this.config.persistence === 'memory'
2211
2214
  ? this.persistence
2212
2215
  : new posthog_persistence_1.PostHogPersistence(__assign(__assign({}, this.config), { persistence: 'sessionStorage' }), isPersistenceDisabled);
2213
- if (storage_1.localStore._is_supported() && storage_1.localStore._get('ph_debug') === 'true') {
2214
- this.config.debug = true;
2216
+ var debugConfigFromLocalStorage = this._checkLocalStorageForDebug(this.config.debug);
2217
+ if ((0, core_1.isBoolean)(debugConfigFromLocalStorage)) {
2218
+ this.config.debug = debugConfigFromLocalStorage;
2215
2219
  }
2216
- if (this.config.debug) {
2217
- config_1.default.DEBUG = true;
2218
- logger_1.logger.info('set_config', {
2219
- config: config,
2220
- oldConfig: oldConfig,
2221
- newConfig: __assign({}, this.config),
2222
- });
2220
+ if ((0, core_1.isBoolean)(this.config.debug)) {
2221
+ if (this.config.debug) {
2222
+ config_1.default.DEBUG = true;
2223
+ storage_1.localStore._is_supported() && storage_1.localStore._set('ph_debug', 'true');
2224
+ logger_1.logger.info('set_config', {
2225
+ config: config,
2226
+ oldConfig: oldConfig,
2227
+ newConfig: __assign({}, this.config),
2228
+ });
2229
+ }
2230
+ else {
2231
+ config_1.default.DEBUG = false;
2232
+ storage_1.localStore._is_supported() && storage_1.localStore._remove('ph_debug');
2233
+ }
2223
2234
  }
2224
2235
  (_b = this.sessionRecording) === null || _b === void 0 ? void 0 : _b.startIfEnabledOrStop();
2225
2236
  (_c = this.autocapture) === null || _c === void 0 ? void 0 : _c.startIfEnabled();
@@ -2810,12 +2821,10 @@ var PostHog = /** @class */ (function () {
2810
2821
  PostHog.prototype.debug = function (debug) {
2811
2822
  if (debug === false) {
2812
2823
  globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.console.log("You've disabled debug mode.");
2813
- localStorage && localStorage.removeItem('ph_debug');
2814
2824
  this.set_config({ debug: false });
2815
2825
  }
2816
2826
  else {
2817
2827
  globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.console.log("You're now in debug mode. All calls to PostHog will be logged in your console.\nYou can disable this with `posthog.debug(false)`.");
2818
- localStorage && localStorage.setItem('ph_debug', 'true');
2819
2828
  this.set_config({ debug: true });
2820
2829
  }
2821
2830
  };
@@ -2924,6 +2933,11 @@ var PostHog = /** @class */ (function () {
2924
2933
  $ai_metric_value: String(metricValue),
2925
2934
  });
2926
2935
  };
2936
+ PostHog.prototype._checkLocalStorageForDebug = function (debugConfig) {
2937
+ var explicitlyFalse = (0, core_1.isBoolean)(debugConfig) && !debugConfig;
2938
+ var isTrueInLocalStorage = storage_1.localStore._is_supported() && storage_1.localStore._get('ph_debug') === 'true';
2939
+ return explicitlyFalse ? false : isTrueInLocalStorage ? true : debugConfig;
2940
+ };
2927
2941
  return PostHog;
2928
2942
  }());
2929
2943
  exports.PostHog = PostHog;