Skip to content

Commit

Permalink
refactor: Remove/deprecate/rename old options (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeelaudibert authored Jan 27, 2025
1 parent ee272df commit ff69389
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
36 changes: 16 additions & 20 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
Compression,
EarlyAccessFeatureCallback,
EventName,
IsFeatureEnabledOptions,
JsonType,
PostHogConfig,
Properties,
Expand Down Expand Up @@ -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,
Expand All @@ -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: {},
Expand All @@ -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<PostHogConfig>): Partial<PostHogConfig> => {
Expand All @@ -205,6 +202,12 @@ export const configRenames = (origConfig: Partial<PostHogConfig>): Partial<PostH
if (!isUndefined(origConfig.disable_cookie)) {
renames.disable_persistence = origConfig.disable_cookie
}
if (!isUndefined(origConfig.store_google)) {
renames.save_campaign_params = origConfig.store_google
}
if (!isUndefined(origConfig.verbose)) {
renames.debug = origConfig.verbose
}
// on_xhr_error is not present, as the type is different to on_request_error

// the original config takes priority over the renames
Expand Down Expand Up @@ -369,6 +372,7 @@ export class PostHog {
const namedPosthog = instances[name] ?? new PostHog()
namedPosthog._init(token, config, name)
instances[name] = namedPosthog

// Add as a property to the primary instance (this isn't type-safe but its how it was always done)
;(instances[PRIMARY_INSTANCE_NAME] as any)[name] = namedPosthog

Expand Down Expand Up @@ -848,13 +852,14 @@ export class PostHog {
// The initial campaign/referrer props need to be stored in the regular persistence, as they are there to mimic
// the person-initial props. The non-initial versions are stored in the sessionPersistence, as they are sent
// with every event and used by the session table to create session-initial props.
if (this.config.store_google) {
if (this.config.save_campaign_params) {
this.sessionPersistence.update_campaign_params()
}
if (this.config.save_referrer) {
this.sessionPersistence.update_referrer_info()
}
if (this.config.store_google || this.config.save_referrer) {

if (this.config.save_campaign_params || this.config.save_referrer) {
this.persistence.set_initial_person_info()
}

Expand Down Expand Up @@ -980,15 +985,6 @@ export class PostHog {
properties['$lib_custom_api_host'] = this.config.api_host
}

if (
this.sessionPropsManager &&
this.config.__preview_send_client_session_params &&
(event_name === '$pageview' || event_name === '$pageleave' || event_name === '$autocapture')
) {
const sessionProps = this.sessionPropsManager.getSessionProps()
properties = extend(properties, sessionProps)
}

let pageviewProperties: Record<string, any>
if (event_name === '$pageview') {
pageviewProperties = this.pageViewManager.doPageView(timestamp, uuid)
Expand Down Expand Up @@ -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)
}

Expand Down
26 changes: 17 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit ff69389

Please sign in to comment.