From ff693894fd02f98a1c037ea34605c506f93d97a2 Mon Sep 17 00:00:00 2001 From: Rafael Audibert <32079912+rafaeelaudibert@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:56:32 -0300 Subject: [PATCH] refactor: Remove/deprecate/rename old options (#1694) --- src/posthog-core.ts | 36 ++++++++++++++++-------------------- src/types.ts | 26 +++++++++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 0748b9641..e7a7b6742 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -34,7 +34,6 @@ import { Compression, EarlyAccessFeatureCallback, EventName, - IsFeatureEnabledOptions, JsonType, PostHogConfig, Properties, @@ -133,20 +132,20 @@ export const defaultConfig = (): PostHogConfig => ({ persistence: 'localStorage+cookie', // up to 1.92.0 this was 'cookie'. It's easy to migrate as 'localStorage+cookie' will migrate data from cookie storage persistence_name: '', loaded: __NOOP, - store_google: true, + save_campaign_params: true, custom_campaign_params: [], custom_blocked_useragents: [], save_referrer: true, capture_pageview: true, capture_pageleave: 'if_capture_pageview', // We'll only capture pageleave events if capture_pageview is also true debug: (location && isString(location?.search) && location.search.indexOf('__posthog_debug=true') !== -1) || false, - verbose: false, cookie_expiration: 365, upgrade: false, disable_session_recording: false, disable_persistence: false, disable_web_experiments: true, // disabled in beta. disable_surveys: false, + disable_external_dependency_loading: false, enable_recording_console_log: undefined, // When undefined, it falls back to the server-side setting secure_cookie: window?.location?.protocol === 'https:', ip: true, @@ -160,8 +159,6 @@ export const defaultConfig = (): PostHogConfig => ({ respect_dnt: false, sanitize_properties: null, request_headers: {}, // { header: value, header2: value } - inapp_protocol: '//', - inapp_link_new_window: false, request_batching: true, properties_string_max_length: 65535, session_recording: {}, @@ -179,16 +176,16 @@ export const defaultConfig = (): PostHogConfig => ({ logger.error(error) }, get_device_id: (uuid) => uuid, - // Used for internal testing - _onCapture: __NOOP, capture_performance: undefined, name: 'posthog', bootstrap: {}, disable_compression: false, session_idle_timeout_seconds: 30 * 60, // 30 minutes person_profiles: 'identified_only', - __add_tracing_headers: false, before_send: undefined, + + // Used for internal testing + _onCapture: __NOOP, }) export const configRenames = (origConfig: Partial): Partial => { @@ -205,6 +202,12 @@ export const configRenames = (origConfig: Partial): Partial if (event_name === '$pageview') { pageviewProperties = this.pageViewManager.doPageView(timestamp, uuid) @@ -1224,7 +1220,7 @@ export class PostHog { * @param {Object|String} prop Key of the feature flag. * @param {Object|String} options (optional) If {send_event: false}, we won't send an $feature_flag_call event to PostHog. */ - isFeatureEnabled(key: string, options?: IsFeatureEnabledOptions): boolean | undefined { + isFeatureEnabled(key: string, options?: { send_event: boolean }): boolean | undefined { return this.featureFlags.isFeatureEnabled(key, options) } diff --git a/src/types.ts b/src/types.ts index 56b9e7bce..db056d90f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -230,17 +230,24 @@ export interface PostHogConfig { /** @deprecated - Use 'persistence_name' instead */ cookie_name?: string loaded: (posthog_instance: PostHog) => void - store_google: boolean + + /** @deprecated - Use `save_campaign_params` instead */ + store_google?: boolean + save_campaign_params: boolean + custom_campaign_params: string[] // a list of strings to be tested against navigator.userAgent to determine if the source is a bot // this is **added to** the default list of bots that we check // defaults to the empty array custom_blocked_useragents: string[] save_referrer: boolean - verbose: boolean capture_pageview: boolean capture_pageleave: boolean | 'if_capture_pageview' + + /** @deprecated Use `debug` instead */ + verbose?: boolean debug: boolean + cookie_expiration: number upgrade: boolean disable_session_recording: boolean @@ -275,8 +282,6 @@ export interface PostHogConfig { xhr_headers?: { [header_name: string]: string } /** @deprecated - use `on_request_error` instead */ on_xhr_error?: (failedRequest: XMLHttpRequest) => void - inapp_protocol: string - inapp_link_new_window: boolean request_batching: boolean properties_string_max_length: number session_recording: SessionRecordingOptions @@ -316,7 +321,6 @@ export interface PostHogConfig { disable_compression: boolean bootstrap: BootstrapConfig segment?: SegmentAnalytics - __preview_send_client_session_params?: boolean /* @deprecated - use `capture_heatmaps` instead */ enable_heatmaps?: boolean capture_heatmaps?: boolean | HeatmapConfig @@ -368,6 +372,14 @@ export interface PostHogConfig { * whether to send a sentinel value for distinct id, device id, and session id, which will be replaced server-side by a cookieless hash * */ __preview_experimental_cookieless_mode?: boolean + + // ------- RETIRED CONFIGS ------- + + /** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */ + inapp_protocol?: string + + /** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */ + inapp_link_new_window?: boolean } export interface OptInOutCapturingOptions { @@ -383,10 +395,6 @@ export interface OptInOutCapturingOptions { secure_cookie: boolean } -export interface IsFeatureEnabledOptions { - send_event: boolean -} - export interface SessionRecordingOptions { blockClass?: string | RegExp blockSelector?: string | null