diff --git a/src/__tests__/autocapture.test.ts b/src/__tests__/autocapture.test.ts index 1cf4ebb2d..a2e8039f7 100644 --- a/src/__tests__/autocapture.test.ts +++ b/src/__tests__/autocapture.test.ts @@ -380,7 +380,7 @@ describe('Autocapture system', () => { beforeEach(() => { posthog.config.rageclick = true // Trigger proper enabling - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) }) it('should capture rageclick', () => { @@ -502,7 +502,7 @@ describe('Autocapture system', () => { it('should not capture events when config returns false, when an element matching any of the event selectors is clicked', () => { posthog.config.autocapture = false - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) const eventElement1 = document.createElement('div') const eventElement2 = document.createElement('div') @@ -524,7 +524,7 @@ describe('Autocapture system', () => { }) it('should not capture events when config returns true but server setting is disabled', () => { - autocapture.afterDecideResponse({ + autocapture.onRemoteConfig({ autocapture_opt_out: true, } as DecideResponse) @@ -932,7 +932,7 @@ describe('Autocapture system', () => { type: 'click', } as unknown as MouseEvent - autocapture.afterDecideResponse({ + autocapture.onRemoteConfig({ elementsChainAsString: true, } as DecideResponse) @@ -1003,7 +1003,7 @@ describe('Autocapture system', () => { beforeEach(() => { document.title = 'test page' posthog.config.mask_all_element_attributes = false - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) }) it('should capture click events', () => { @@ -1056,7 +1056,7 @@ describe('Autocapture system', () => { 'when client side config is %p and remote opt out is %p - autocapture enabled should be %p', (clientSideOptIn, serverSideOptOut, expected) => { posthog.config.autocapture = clientSideOptIn - autocapture.afterDecideResponse({ + autocapture.onRemoteConfig({ autocapture_opt_out: serverSideOptOut, } as DecideResponse) expect(autocapture.isEnabled).toBe(expected) @@ -1065,12 +1065,12 @@ describe('Autocapture system', () => { it('should call _addDomEventHandlders if autocapture is true in client config', () => { posthog.config.autocapture = true - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) expect(autocapture['_addDomEventHandlers']).toHaveBeenCalled() }) it('should not call _addDomEventHandlders if autocapture is opted out in server config', () => { - autocapture.afterDecideResponse({ autocapture_opt_out: true } as DecideResponse) + autocapture.onRemoteConfig({ autocapture_opt_out: true } as DecideResponse) expect(autocapture['_addDomEventHandlers']).not.toHaveBeenCalled() }) @@ -1078,16 +1078,16 @@ describe('Autocapture system', () => { expect(autocapture['_addDomEventHandlers']).not.toHaveBeenCalled() posthog.config.autocapture = false - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) expect(autocapture['_addDomEventHandlers']).not.toHaveBeenCalled() }) it('should NOT call _addDomEventHandlders when the token has already been initialized', () => { - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) expect(autocapture['_addDomEventHandlers']).toHaveBeenCalledTimes(1) - autocapture.afterDecideResponse({} as DecideResponse) + autocapture.onRemoteConfig({} as DecideResponse) expect(autocapture['_addDomEventHandlers']).toHaveBeenCalledTimes(1) }) }) diff --git a/src/__tests__/extensions/exception-autocapture/exception-observer.test.ts b/src/__tests__/extensions/exception-autocapture/exception-observer.test.ts index ad934e2b1..654a8da25 100644 --- a/src/__tests__/extensions/exception-autocapture/exception-observer.test.ts +++ b/src/__tests__/extensions/exception-autocapture/exception-observer.test.ts @@ -67,7 +67,7 @@ describe('Exception Observer', () => { describe('when enabled', () => { beforeEach(() => { - exceptionObserver.afterDecideResponse({ autocaptureExceptions: true } as DecideResponse) + exceptionObserver.onRemoteConfig({ autocaptureExceptions: true } as DecideResponse) }) it('should instrument handlers when started', () => { @@ -173,7 +173,7 @@ describe('Exception Observer', () => { window!.onerror = originalOnError window!.onunhandledrejection = originalOnUnhandledRejection - exceptionObserver.afterDecideResponse({ autocaptureExceptions: true } as DecideResponse) + exceptionObserver.onRemoteConfig({ autocaptureExceptions: true } as DecideResponse) }) it('should wrap original onerror handler if one was present when wrapped', () => { @@ -232,7 +232,7 @@ describe('Exception Observer', () => { describe('when disabled', () => { beforeEach(() => { - exceptionObserver.afterDecideResponse({ autocaptureExceptions: false } as DecideResponse) + exceptionObserver.onRemoteConfig({ autocaptureExceptions: false } as DecideResponse) }) it('cannot be started', () => { diff --git a/src/__tests__/extensions/replay/sessionrecording.test.ts b/src/__tests__/extensions/replay/sessionrecording.test.ts index d786d56e3..a0c676588 100644 --- a/src/__tests__/extensions/replay/sessionrecording.test.ts +++ b/src/__tests__/extensions/replay/sessionrecording.test.ts @@ -486,7 +486,7 @@ describe('SessionRecording', () => { }) it('loads script based on script config', () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', scriptConfig: { script: 'experimental-recorder' } }, }) @@ -553,7 +553,7 @@ describe('SessionRecording', () => { windowId: 'windowId', }) - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: undefined })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: undefined })) expect(sessionRecording['status']).toBe('disabled') expect(sessionRecording['buffer'].data.length).toEqual(0) expect(posthog.capture).not.toHaveBeenCalled() @@ -564,7 +564,7 @@ describe('SessionRecording', () => { expect(loadScriptMock).toHaveBeenCalled() expect(sessionRecording['status']).toBe('buffering') - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) expect(sessionRecording['status']).toBe('active') }) @@ -573,14 +573,14 @@ describe('SessionRecording', () => { expect(loadScriptMock).toHaveBeenCalled() expect(sessionRecording['isSampled']).toBe(null) - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) expect(sessionRecording['isSampled']).toBe(null) }) it('stores true in persistence if recording is enabled from the server', () => { posthog.persistence?.register({ [SESSION_RECORDING_ENABLED_SERVER_SIDE]: undefined }) - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) expect(posthog.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE)).toBe(true) }) @@ -588,7 +588,7 @@ describe('SessionRecording', () => { it('stores true in persistence if canvas is enabled from the server', () => { posthog.persistence?.register({ [SESSION_RECORDING_CANVAS_RECORDING]: undefined }) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', recordCanvas: true, canvasFps: 6, canvasQuality: '0.2' }, }) @@ -604,7 +604,7 @@ describe('SessionRecording', () => { it('stores false in persistence if recording is not enabled from the server', () => { posthog.persistence?.register({ [SESSION_RECORDING_ENABLED_SERVER_SIDE]: undefined }) - sessionRecording.afterDecideResponse(makeDecideResponse({})) + sessionRecording.onRemoteConfig(makeDecideResponse({})) expect(posthog.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE)).toBe(false) }) @@ -612,7 +612,7 @@ describe('SessionRecording', () => { it('stores sample rate', () => { posthog.persistence?.register({ SESSION_RECORDING_SAMPLE_RATE: undefined }) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: '0.70' }, }) @@ -624,7 +624,7 @@ describe('SessionRecording', () => { it('starts session recording, saves setting and endpoint when enabled', () => { posthog.persistence?.register({ [SESSION_RECORDING_ENABLED_SERVER_SIDE]: undefined }) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/ses/' }, }) @@ -642,7 +642,7 @@ describe('SessionRecording', () => { it('does not emit to capture if the sample rate is 0', () => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: '0.00' }, }) @@ -657,7 +657,7 @@ describe('SessionRecording', () => { it('does emit to capture if the sample rate is null', () => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: null }, }) @@ -669,7 +669,7 @@ describe('SessionRecording', () => { it('stores excluded session when excluded', () => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: '0.00' }, }) @@ -684,7 +684,7 @@ describe('SessionRecording', () => { _emit(createIncrementalSnapshot({ data: { source: 1 } })) expect(posthog.capture).not.toHaveBeenCalled() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: '1.00' }, }) @@ -704,7 +704,7 @@ describe('SessionRecording', () => { it('sets emit as expected when sample rate is 0.5', () => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', sampleRate: '0.50' }, }) @@ -758,7 +758,7 @@ describe('SessionRecording', () => { it('skips when any config variable is missing', () => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', recordCanvas: null, canvasFps: null, canvasQuality: null }, }) @@ -837,7 +837,7 @@ describe('SessionRecording', () => { windowId: 'windowId', }) - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) // next call to emit won't flush the buffer // the events aren't big enough @@ -869,7 +869,7 @@ describe('SessionRecording', () => { }) it('buffers emitted events', () => { - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() expect(loadScriptMock).toHaveBeenCalled() @@ -904,7 +904,7 @@ describe('SessionRecording', () => { }) it('flushes buffer if the size of the buffer hits the limit', () => { - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() expect(loadScriptMock).toHaveBeenCalled() const bigData = 'a'.repeat(RECORDING_MAX_EVENT_SIZE * 0.8) @@ -949,7 +949,7 @@ describe('SessionRecording', () => { }) it('flushes buffer if the session_id changes', () => { - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() expect(sessionRecording['buffer'].sessionId).toEqual(sessionId) @@ -1061,7 +1061,7 @@ describe('SessionRecording', () => { it('can emit when there are circular references', () => { posthog.config.session_recording.compress_events = false - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() const someObject = { emit: 1 } @@ -1362,7 +1362,7 @@ describe('SessionRecording', () => { beforeEach(() => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) expect(sessionRecording['status']).toEqual('active') startingTimestamp = sessionRecording['_lastActivityTimestamp'] @@ -1718,7 +1718,7 @@ describe('SessionRecording', () => { expect(sessionRecording['_linkedFlag']).toEqual(null) expect(sessionRecording['_linkedFlagSeen']).toEqual(false) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', linkedFlag: 'the-flag-key' } }) ) @@ -1741,7 +1741,7 @@ describe('SessionRecording', () => { expect(sessionRecording['_linkedFlag']).toEqual(null) expect(sessionRecording['_linkedFlagSeen']).toEqual(false) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', linkedFlag: { flag: 'the-flag-key', variant: 'test-a' } }, }) @@ -1766,7 +1766,7 @@ describe('SessionRecording', () => { expect(sessionRecording['_linkedFlag']).toEqual(null) expect(sessionRecording['_linkedFlagSeen']).toEqual(false) - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', linkedFlag: 'the-flag-key' } }) ) @@ -1793,7 +1793,7 @@ describe('SessionRecording', () => { expect(sessionRecording['_linkedFlagSeen']).toEqual(false) expect(sessionRecording['status']).toEqual('buffering') - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', @@ -1870,7 +1870,7 @@ describe('SessionRecording', () => { }) it('can set minimum duration from decide response', () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { minimumDurationMilliseconds: 1500 }, }) @@ -1879,7 +1879,7 @@ describe('SessionRecording', () => { }) it('does not flush if below the minimum duration', () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { minimumDurationMilliseconds: 1500 }, }) @@ -1899,7 +1899,7 @@ describe('SessionRecording', () => { }) it('does flush if session duration is negative', () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { minimumDurationMilliseconds: 1500 }, }) @@ -1924,7 +1924,7 @@ describe('SessionRecording', () => { }) it('does not stay buffering after the minimum duration', () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { minimumDurationMilliseconds: 1500 }, }) @@ -1970,7 +1970,7 @@ describe('SessionRecording', () => { }) sessionRecording = new SessionRecording(posthog) - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() expect(loadScriptMock).toHaveBeenCalled() @@ -2089,7 +2089,7 @@ describe('SessionRecording', () => { beforeEach(() => { posthog.config.session_recording.compress_events = true - sessionRecording.afterDecideResponse(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) + sessionRecording.onRemoteConfig(makeDecideResponse({ sessionRecording: { endpoint: '/s/' } })) sessionRecording.startIfEnabledOrStop() }) @@ -2271,7 +2271,7 @@ describe('SessionRecording', () => { describe('URL blocking', () => { beforeEach(() => { sessionRecording.startIfEnabledOrStop() - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', @@ -2343,7 +2343,7 @@ describe('SessionRecording', () => { }) it('flushes buffer and starts when sees event', async () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', @@ -2371,7 +2371,7 @@ describe('SessionRecording', () => { }) it('starts if sees an event but still waiting for a URL', async () => { - sessionRecording.afterDecideResponse( + sessionRecording.onRemoteConfig( makeDecideResponse({ sessionRecording: { endpoint: '/s/', diff --git a/src/__tests__/extensions/web-vitals.test.ts b/src/__tests__/extensions/web-vitals.test.ts index 5cd284a13..b28aeb125 100644 --- a/src/__tests__/extensions/web-vitals.test.ts +++ b/src/__tests__/extensions/web-vitals.test.ts @@ -113,7 +113,7 @@ describe('web vitals', () => { assignableWindow.__PosthogExtensions__.loadExternalDependency = loadScriptMock // need to force this to get the web vitals script loaded - posthog.webVitalsAutocapture!.afterDecideResponse({ + posthog.webVitalsAutocapture!.onRemoteConfig({ capturePerformance: { web_vitals: true }, } as unknown as DecideResponse) @@ -244,7 +244,7 @@ describe('web vitals', () => { 'when client side config is %p and remote opt in is %p - web vitals enabled should be %p', (clientSideOptIn, serverSideOptIn, expected) => { posthog.config.capture_performance = { web_vitals: clientSideOptIn } - posthog.webVitalsAutocapture!.afterDecideResponse({ + posthog.webVitalsAutocapture!.onRemoteConfig({ capturePerformance: { web_vitals: serverSideOptIn }, } as DecideResponse) expect(posthog.webVitalsAutocapture!.isEnabled).toBe(expected) diff --git a/src/__tests__/heatmaps.test.ts b/src/__tests__/heatmaps.test.ts index 0f1588d2c..5168c8a37 100644 --- a/src/__tests__/heatmaps.test.ts +++ b/src/__tests__/heatmaps.test.ts @@ -217,7 +217,7 @@ describe('heatmaps', () => { (deprecatedclientSideOptIn, clientSideOptIn, serverSideOptIn, expected) => { posthog.config.enable_heatmaps = deprecatedclientSideOptIn posthog.config.capture_heatmaps = clientSideOptIn - posthog.heatmaps!.afterDecideResponse({ + posthog.heatmaps!.onRemoteConfig({ heatmaps: serverSideOptIn, } as DecideResponse) expect(posthog.heatmaps!.isEnabled).toBe(expected) diff --git a/src/__tests__/posthog-core.ts b/src/__tests__/posthog-core.ts index b3f2c1c9c..9161fee2c 100644 --- a/src/__tests__/posthog-core.ts +++ b/src/__tests__/posthog-core.ts @@ -842,7 +842,7 @@ describe('posthog core', () => { expect(posthog.persistence.register).not.toHaveBeenCalled() // FFs are saved this way // Session recording - expect(posthog.sessionRecording.afterDecideResponse).not.toHaveBeenCalled() + expect(posthog.sessionRecording.onRemoteConfig).not.toHaveBeenCalled() }) describe('device id behavior', () => { diff --git a/src/__tests__/site-apps.ts b/src/__tests__/site-apps.ts index 7964a7e17..aea6407a5 100644 --- a/src/__tests__/site-apps.ts +++ b/src/__tests__/site-apps.ts @@ -224,7 +224,7 @@ describe('SiteApps', () => { describe('afterDecideResponse', () => { it('sets loaded to true and enabled to false when response is undefined', () => { - siteAppsInstance.afterDecideResponse(undefined) + siteAppsInstance.onRemoteConfig(undefined) expect(siteAppsInstance.loaded).toBe(true) expect(siteAppsInstance.enabled).toBe(false) @@ -240,7 +240,7 @@ describe('SiteApps', () => { ], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) expect(siteAppsInstance.appsLoading.size).toBe(2) expect(siteAppsInstance.loaded).toBe(false) @@ -261,7 +261,7 @@ describe('SiteApps', () => { siteApps: [{ id: '1', url: '/site_app/1' }], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) expect(siteAppsInstance.loaded).toBe(true) expect(siteAppsInstance.enabled).toBe(false) @@ -276,7 +276,7 @@ describe('SiteApps', () => { siteApps: [{ id: '1', url: '/site_app/1' }], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) // Wait for the simulated async loading to complete setTimeout(() => { @@ -293,7 +293,7 @@ describe('SiteApps', () => { siteApps: [{ id: '1', url: '/site_app/1' }], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) expect(assignableWindow['__$$ph_site_app_1']).toBe(posthog) expect(typeof assignableWindow['__$$ph_site_app_1_missed_invocations']).toBe('function') @@ -312,7 +312,7 @@ describe('SiteApps', () => { siteApps: [{ id: '1', url: '/site_app/1' }], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) expect(logger.error).toHaveBeenCalledWith( 'PostHog site apps are disabled. Enable the "opt_in_site_apps" config to proceed.' @@ -327,7 +327,7 @@ describe('SiteApps', () => { siteApps: [], } as DecideResponse - siteAppsInstance.afterDecideResponse(response) + siteAppsInstance.onRemoteConfig(response) expect(siteAppsInstance.loaded).toBe(true) expect(siteAppsInstance.enabled).toBe(false) diff --git a/src/__tests__/web-experiments.test.ts b/src/__tests__/web-experiments.test.ts index 8e9ace341..2e5df4f11 100644 --- a/src/__tests__/web-experiments.test.ts +++ b/src/__tests__/web-experiments.test.ts @@ -128,6 +128,7 @@ describe('Web Experimentation', () => { .fn() .mockImplementation(({ callback }) => callback({ statusCode: 200, json: experimentsResponse })), consent: { isOptedOut: () => true } as unknown as ConsentManager, + onFeatureFlags: jest.fn(), }) posthog.requestRouter = new RequestRouter(posthog) @@ -170,7 +171,7 @@ describe('Web Experimentation', () => { function assertElementChanged(variant: string, expectedProperty: string, value: string) { const elParent = createTestDocument() webExperiment = new WebExperiments(posthog) - webExperiment.afterDecideResponse({ + webExperiment.onRemoteConfig({ featureFlags: { 'signup-button-test': variant, }, @@ -200,7 +201,7 @@ describe('Web Experimentation', () => { webExperiment._is_bot = () => true const elParent = createTestDocument() - webExperiment.afterDecideResponse({ + webExperiment.onRemoteConfig({ featureFlags: { 'signup-button-test': 'Sign me up', }, @@ -262,6 +263,7 @@ describe('Web Experimentation', () => { .fn() .mockImplementation(({ callback }) => callback({ statusCode: 200, json: expResponse })), consent: { isOptedOut: () => true } as unknown as ConsentManager, + onFeatureFlags: jest.fn(), }) posthog.requestRouter = new RequestRouter(disabledPostHog) diff --git a/src/decide.ts b/src/decide.ts index b82ae5e60..9a84b4d6a 100644 --- a/src/decide.ts +++ b/src/decide.ts @@ -118,6 +118,7 @@ export class Decide { } private onRemoteConfig(config?: RemoteConfig): void { + // NOTE: Once this is rolled out we will remove the "decide" related code above. Until then the code duplication is fine. if (!config) { logger.error('Failed to fetch remote config from PostHog.') return diff --git a/src/posthog-core.ts b/src/posthog-core.ts index e27f4fd80..e9ce4ed5e 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -572,7 +572,7 @@ export class PostHog { this.sessionRecording?.onRemoteConfig(response) this.autocapture?.onRemoteConfig(response) this.heatmaps?.onRemoteConfig(response) - this.experiments?.afterDecideResponse(response) + this.experiments?.onRemoteConfig(response) this.surveys?.onRemoteConfig(response) this.webVitalsAutocapture?.onRemoteConfig(response) this.exceptionObserver?.onRemoteConfig(response) diff --git a/src/web-experiments.ts b/src/web-experiments.ts index ca48ba115..7a15762e9 100644 --- a/src/web-experiments.ts +++ b/src/web-experiments.ts @@ -65,7 +65,7 @@ export class WebExperiments { }) } - afterDecideResponse(response: DecideResponse) { + onRemoteConfig(response: DecideResponse) { if (this._is_bot()) { WebExperiments.logInfo('Refusing to render web experiment since the viewer is a likely bot') return